Sam Sam - 8 days ago 6
React JSX Question

Handling logic in dumb component

Is the following the right way to handle some logic in dumb components in React?

const MyDumbContainer = ({myObject}) => {

const myRenderFunction = () {

if(myObject === null) return null;

return(
<div>
{myObject.someData}
</div>
);
}

return(
<div>{myRenderFunction()}</div>
);
}

Answer

More elegantly:

const MyDumbContainer = ({ myObject }) => (myObject !== null)
    ? <div>{myObject.someData}</div>
    : null
}