[英]React: useState() vs useRef()
I've gone through the React Docs once.我已经浏览过一次 React Docs。
I'm trying to compare useState() with useRef() in my mind…我试图在我的脑海中比较 useState() 和 useRef() ......
Commonalities to both useState() and useRef(): useState() 和 useRef() 的共同点:
Differences between useState() and useRef(): useState() 和 useRef() 的区别:
…And this previous Stackoverflow question adds: …… 之前的 Stackoverflow 问题补充说:
So I have 3 questions so far:所以到目前为止我有3个问题:
Basically your comparison is correct, but as already was mentioned in comments they serve different purposes.基本上你的比较是正确的,但正如评论中已经提到的,它们有不同的用途。 You just need to know is that
useRef
basically is syntax sugar :你只需要知道
useRef
基本上是语法糖:
useRef() is basically useState({current: initialValue })[0]
useRef() 基本上是 useState({current: initialValue })[0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.