How to reload a component (part of page) in reactjs?

The easiest way I have found out is to set a seed state, and use that in the key attribute of the rendered component. Whenever the seed changes now the component will be reloaded.

       const [seed, setSeed] = useState(1);
       const reset = () => {
            setSeed(Math.random());
        }
       <Component key={seed}/>
       <Button onClick={reset}>Reset</Button>

Whenever the Reload button is pressed now the component I need will be rerendered.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)