2021
06-04
06-04
React Hook用法示例详解(6个常见hook)
1、useState:让函数式组件拥有状态用法示例://计数器import{useState}from'react'constTest=()=>{const[count,setCount]=useState(0);return(<><h1>点击了{count}次</h1><buttononClick={()=>setCount(count+1)}>+1</button></>);}exportdefaultTestPS:class组件中this.setState更新是state是合并,useState中setState是替换。例如://错误示例i...
继续阅读 >