How can I force component to re-render with hooks in React?

前端 未结 16 2229
误落风尘
误落风尘 2020-11-29 00:28

Considering below hooks example

   import { useState } from \'react\';

   function Example() {
       const [count, setCount] = useState(0);

       return         


        
16条回答
  •  迷失自我
    2020-11-29 01:08

    This will render depending components 3 times (arrays with equal elements aren't equal):

    const [msg, setMsg] = useState([""])
    
    setMsg(["test"])
    setMsg(["test"])
    setMsg(["test"])
    

提交回复
热议问题