Menu

gitpiper

useUpdate react Code Snippet in 2023

componentsreducerbeginner

Last Updated: 3 February 2023

Forces the component to re-render when called.

  • Use the useReducer() hook that creates a new object every time it's updated and return its dispatch.
const useUpdate = () => { const [, update] = React.useReducer(() => ({})); return update; };
const MyApp = () => { const update = useUpdate(); return ( <> <div>Time: {Date.now()}</div> <button onClick={update}>Update</button> </> ); }; ReactDOM.render(<MyApp />, document.getElementById('root'));

react snippet similar to useUpdate For You in February 2023

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2023 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️