it seems like a dumb question but I didn't find any answer on SO or Google...
I want to make a simple admin panel menu which could expose a method to dynamically add a menu item like so:
function SomeRandomComponent() {
const targetRoute = `my/route`
sideMenu.addMenuItem('Link label', targetRoute)
return <Route path={targetRoute}>
<div>
My page
</div>
</Route>
}
I didn't manage to find a good way to expose the setState method to other component. And I don't see another solution.
Have you got any clues on how to achieve that please?
Actually there are many ways to do that but the most elegant is using ContextAPI or useReducer Hook in your app. Then, menu items could be dynamically iterated from the state.
If the app has implemented Redux it's worth to do it there. But don't overkill by implementing Redux exclusively for that thing.