I'm building a Header component which is used throughout my application. I'm using React and Redux (obvz) to hold a default state for the Header e.g. in the header reducer's default state argument:
state = {
showUserMenu: true,
redirectUrl: '/'
}
This is perfect for all the components where this is true, but for some routes/components I want the header to not show the user menu.
So when those components mount I dispatch an action to HIDE_USER_MENU.
The problem is that because the default is set to true, the userMenu will be there initially, and even if the dispatch is called in componentWillMount, there will be a split second where the userMenu shows.
So don't have a default? But then the reverse is true, it defaults to not showing the menu and only appears once the action has processed.
This is nice, but it didn't go just a step further (for my example) and explain how the reducer would be chosen based on either route or component.
I have also tried firing actions based on location.pathname using react-router-redux, but even this does not happen quickly enough to avoid FOUH (flash of unwanted header! :'( )
I wondered if there was an established pattern for dynamically loading an initial state, that is guaranteed to appear on initial render.
Hope it's clear what I was asking, any help much appreciated!