Whats the difference between passing a ReactElement
as a property:
<RenderParam ReactElement={<Counter />} />
function RenderParam({ ReactElement }) {
return <div>{ReactElement}</div>;
}
and passing a function that returns a ReactElement
:
const instantiatedCounter = () => <Counter />;
<RenderParam ReactElement={instantiatedCounter} />
function RenderParam({ ReactElement }) {
return <div> <ReactElement /> </div>
}
I see there are differences in the lifecycle:
- Every time the parent react element updates, the mount cycle of
Counter
is executed for the second case:
ReactElement changed (at RenderParam lifecycle)
component did mount (at Counter)
- Also the second case lose its state every time the parent component renders.
I dont see whats difference between them. Why first case its able to keep its state?