Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
876 views
in Technique[技术] by (71.8m points)

React useState 是不是用来实时更新数据用的?

在看别人的项目的代码.

看到一堆类似这种格式的代码.

const [ the_Variable1,setVariable1 ] = React.useState({})

我不太明白用途.

如果要定义初始化一个变量,通常不是直接let xxxx = {} 不就好了吗?
或者 var xxx = {} 不就好了

这里为什么要用 const (常量?)

还有为什么要用这个useState() 呢.

还有就是 为什么要把 变量和这个像是函数的放在同一个array里面
[the_Variable1,setVariable1]

感觉这种语法对我新手来说好难理解.

Vue 好像都很简单呀.直接设置个变量就好了.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

建议先看看React Hooks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...