React component render twice on useState().
const [value, setValue] = useState('');
Each time value is changed on setValue():
setValue('hello world')
console.log('render')
The component is rendered twice (render appears twice in console).
-
Go to
index.jsfile insrcfolder.srcfolder is located inrootfolder
-
Remove
<React.StrictMode>,</React.StrictMode>,from the code.
ReactDOM.render(
<React.StrictMode>
<App />,
</React.StrictMode>,
document.getElementById('root')
);
ReactDOM.render(
<App />,
document.getElementById('root')
);
This will solve the rendering twice problem.
This is not a bug, but a feature provided by React to catch outdated functions, you can Google if you want to find out more.