I'm having the following problem:
I have a Sidebar component in which I generated three buttons through the map() function. I put the buttons in a MUI Grid and applied styling on this grid.
const Sidebar = () => {
const classes = useStyles()
const navigate = useNavigate()
return (
<Grid container
className={classes.containerStyling}
direction="column">
<Grid item className={classes.gridItemStyling}>
{insurances.map((item, index) =>
<Button
key={index}
className={classes.buttonListStyling}>
<Grid container direction="column" className={classes.listItemStyling}>
<Grid item>
<Typography variant="h2">
{item.headline}
</Typography>
</Grid>
</Grid>
</Button>)}
</Grid>
</Grid>
)
}
export default Sidebar
Now I would like to render a headline next to my sidebar depending on which button is clicked. The Headline will have it's own styling. I know i need a hook:
const [hasRender, setRender] = useState(false);
const onShow = React.useCallback(() => setRender(true), [])
<Button
key={index}
className={classes.buttonListStyling}
onClick={onShow}>
</Button>
Then I have to check if 'visible' is true and render my Component.
{visible && <HeadlineContent/>}
The problem is that all the Sidebar styling is applied on the component HeadlineContent and I cannot figure out how to render the component outside the Grid so the correct styling is applied.
And how can I access the buttons text to dynamically create the headline with the same text?
I hope it is understandable.