I was just doing some experimentation and I noticed if I have:
const Component1 = () => {
console.log("Component1");
return <div>Component1</div>;
};
const Component2 = () => {
console.log("Component2");
return <div>Component2</div>;
};
Now when using the components like this:
export default function App() {
const [state, setState] = useState(false);
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<Component1 />
{Component2()}
<button onClick={setState.bind(null, !state)}>Change State</button>
</div>
);
}
I noticed that in console.log component2 appears before component1 even tho they are rendered in the correct order, why does this happen?