I have a component that I want to use as a template and it can be passed various values. However, if and when that value doesn't exist, the component returns Cannot read value of undefined
.
The component:
const Component = ({ value }) => (
<div>
<p>{!value ? '' : value}</p>
</div>
)
And then rendering the template with different values...
<Component value={object1.value} />
<Component value={object2.value} /> // object2 doesn't exist, so error thrown
How to I get the component to render null
, (or something else) if the props
it receives don't exist? Or is there a better solution?