React: useState or useRef?

后端 未结 2 1152
不思量自难忘°
不思量自难忘° 2020-12-23 16:12

I am reading about React useState() and useRef() at \"Hooks FAQ\" and I got confused about some of the use cases that seems to have solution with

2条回答
  •  借酒劲吻你
    2020-12-23 17:07

    The main difference between both is :

    useState causes re-render, useRef does not.

    The common between them is, both useState and useRef can remember their data after re-renders. So if your variable is something that decides a view layer render, go with useState. Else use useRef

    I would suggest reading this article.

提交回复
热议问题