I'm having trouble with the first render of my application. I know the issue is because initially my 'const name' is undefined. When I set it to something such as a string, the app will load, and then I can put the original code back in and the app will work like it's supposed to. But if I refresh, I get the error again. Here is my code:
const HomePage = (props) => {
const name = props.name.newMovement.movementName;
const displayMovementButtons = () => {
if (!name) {
return (
<div className={classes.noMovementsMessage} >Click add button to begin</div>
)
}
return (
<Button
className={classes.movementButtons}
onClick={() => history.push('/movement/:id')}
>
<div className={classes.movementName} >{name}</div>
</Button>
)
};
So, 'name' is what starts off as undefined. How can I restructure my code so that it will do the initial render?