react——useState钩子函数的用法清晰讲解

代码

const [something, setSomething] = useState(false)

讲解

  1. useState方法是一个react自带的钩子函数;
  2. something是由useState函数新创建的一个State;
  3. useState方法的参数作为新的State(也就是something)的值;
  4. setSomething是一个函数,用于以后更新这个State;例如:
setSomething(true);//将something这个State更新为true
  1. useState方法会导致重新渲染;

猜你喜欢

转载自blog.csdn.net/qq_45895576/article/details/113093631