0

When I use console.log to test my app, it logs the data two times here an screenshot and the code

function App() {
const arr = ["one", "two", "three"];
console.log("test");
console.log(arr);
return (
   <p>test</p>
 );
}

export default App;

enter image description here

as you can see I use console.log once for each variable and its log it twice the same thing with error

npm version is 8.19.2

and node v16.16.0

I use npx create-react-app

2 Answers 2

4

The double rendering is caused by React StrictMode, it only happens in the development environment.

If you want to get rid of it, remove <React.StrictMode> that wraps your app. It should be in src/index.js

Sign up to request clarification or add additional context in comments.

Comments

2

Are you using react 18? This was a new thing added and you should not need to worry about it. When strict mode (only in development mode) is enabled, there will be a second run of the rendering function. This is development-only behavior helps you keep components pure

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.