As I understand it, action creators have no idea about the state, and reducers are not allowed to start new actions. So, how do you define an action based on state - does it need to be done in the render function?
As an example, I have a component that lists the names for a set of elements. This data is stored in state.matches
. By clicking on an item, you should open a detailed view in my component Entries
.
I currently have this action creator that downloads a record and runs an action addEntry
that causes the relay to Entries
add data to the cache in state.entries.
export function getEntryFromId(id) {
return function(dispatch) {
dispatch(lookupInit(id));
fetch('/register/id/' + id)
.then( res => res.json() )
.then( res => dispatch(addEntry(res[0])) )
.catch( err => dispatch({ type: ENTRY_LOOKUP_FAIL }) );
}
}
Currently, it is always loading new data because it cannot check the cache.
id
SHOW_THIS_NEXT , , , . .
.