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

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

    You can simply define the useState like that:

    const [, forceUpdate] = React.useState(0);
    

    And usage: forceUpdate(n => !n)

    Hope this help !

提交回复
热议问题