Should we recalculate UI state when props change?
If your UI state depends on props:
@ui({
state: {
name: (props) => props.somethingFromAync
}
})
We'll calculate the default UI on mount and never recalculate when the async call fetches.
Should we?
Pros
- It alleviates async functionality
Cons 2. You might be overriding explicitly set UI state from a user's interaction. This is bad.
Initial thoughts are that if this is an async request, you probably want to defer rendering the component with UI state until that request has finished.
To chime in on this, after running into this issue and thinking 'why is my UI state not updating?!' and then thinking about it some more. I think I agree with how it is implemented just now. For my use-case that I ran into yesterday, I have dropped redux-ui for that, however as a concept I think the way is it just now actually is the 'better' way of doing this.
Thanks for the comment @rogy. Can you explain why you had to drop redux-ui? Would be interesting to see if we can create a solution that works for you
Sure, I was using redux-ui inside a modal window.
The modal window contains a component that presents a list of items than can be selected, or unselected (like a multi select)
The modal window also contains a 'create new' button than takes you to another 'builder modal' which is an external application.
The modal finally contains a save button and a cancel button. Global store of selected items is only updated after hitting save, so all selections/deselections inside the modal are tracked by redux-ui
On complete of the 'builder modal' we recieve via postmessage a 'new item' that gets pushed into the store that powers the first modal. This re-renders the 'item list' with the newly created item, but by default we want to select this (but not at the global store level because save has not been hit)
This is where we had the problem of redux-ui not updating its selections which are based on props on a re-render, only on the init.
@tonyhb An option might be to provide another key to the config called nextState, which is called on componentWillUpdate. Then you can recalculate the state with the new props.
The hardest part is determining should the component update.
imo we should add this functionality. I am basing my ui-state on an async requests that i call in componentDidMount passed through as a prop and this is not updating my ui-state. Without this i have to manually update my ui-state after the async call which is very annoying...
My idea is using redux-ui to monitor my login state basic on connecting the redux store at root container. Without recalculation, I have to connect any component. It is annoying