Stop using useEffect hook to initialize your React components
A simple technique to deal with code that needs to run only once in a component.
A simple technique to deal with code that needs to run only once in a component.
You don't alway need a state management library or resorting to convoluted solutions to pickup changes outside your component. Here is an example of using React's useState
and useEffect
hooks to rerender a component when something outside of it changes and not even in a parent component.
Follow these steps to start and deploy a new React project right from your localhost with support for TypeScript, serverless, and routing using Vite and Vercel CLI...
React tips and tricks...