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

前端 未结 16 2234
误落风尘
误落风尘 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:10

    Solution in one single line:

    const [,forceRender] = useReducer((s) => s+1, 0)
    

    You can learn about useReducer here. https://reactjs.org/docs/hooks-reference.html#usereducer

提交回复
热议问题