SOLVED
@jonahe helped me realise I was storing stale data in my component state resulting in a mismatch between the redux and component store.
@vs1682 pointed out that the store update check is relatively shallow so shouldn't be relied on for deep nested changes.
Original question:
I'm using promise based actions in redux and am running into the following issue: once my state updates (verified per redux logger) the visual component does not reflect this.
Action flow:
- Form is submitted (example: the bio property changes)
- Smart component triggers a dispatch of an action
- Action works as intended and triggers reducer
- State updates well (reflected in redux logger in console)
- Interface does not reflect the change (but the state certainly does)
As per the above I'm quite confident my actions and reducers are fine. I suspect I'm overlooking something in the redux > visual flow.
The below is isolated code. I took away jsx etc that is not relevant.
Map state to props for the smart component:
export default connect( store => ( {
user: store.user ? true : false,
contacts: store.contacts
} ) )( ContactList )
The smart component
<Person person = { this.state.showingperson } />
The person prop is set through:
showPerson( e ) {
e.preventDefault( )
const showingperson = this.props.contacts.object[e.target.id]
this.setState( { ...this.state, showingperson: showingperson } )
}
The dumb component:
export const Person = ( { person } ) => {
return <div id="persontable" className="backdrop">
<div className = 'modal col l6 m12 s12 center'>
<p>Bio: { person.bio }.</p>
</div>
</div>
}
Edit: Reducer code:
import moment from 'moment'
const contactsReducer = ( state = { array: [], object: {} }, action ) => {
switch( action.type ) {
case 'UPDATE_FULFILLED':
case 'GETALL_FULFILLED':
// action.payload is an array of contacts resulting from a transformed firebase call
return action.payload ? action.payload : state
break
case 'CLEAR_FULFILLED':
return null
break
default:
return state
}
}
export default contactsReducer