Answer the question
In order to leave comments, you need to log in
Why does a component with React.useState() render twice?
This code will print "App" to the console once.
import React from "react";
export default function App() {
console.log('App');
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
</div>
);
}
import React from "react";
export default function App() {
console.log('App');
const [foo, setFoo] = React.useState(1);
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
</div>
);
}
const [foo, setFoo] = React.useState(1);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question