I've got a component like this:
const Foo = () => (
<div>
<h1>Hello world!</h1>
</div>
)
Note that it doesn't take any props; it returns the same JSX on every render
Could this be used as just a constant instead of a function?
const Foo = (
<div>
<h1>Hello world!</h1>
</div>
)
or will React have problems re-using the exact same React.createElement()
result across re-renders and - more likely - in different DOM contexts throughout the app?
const OtherComponent = ({ ... }) => (
<div>
{Foo}
{...}
</div>
)
const OtherOtherComponent = ({ ... }) => (
<span>
{Foo}
</span>
)
EDIT: It crossed my mind that any hooks getting called inside child components are probably going to get messed up by this, so it's probably a bad idea.
EDIT 2: Disregard the first "EDIT"; I tested it out and was surprised to find that a hook buried under the const react-node does actually get called multiple times. I'm leaning towards thinking this is indeed safe, but would still like confirmation from someone more familiar with React's internals.