Reputation: 6290
I have redux and react working correctly I believe and I have a child component firing off an action which then makes it as a new state to the parent component's mapStatetoDispatch
method. However, while I can confirm through the console log that this state is indeed new, it never hits the render method (the props come back as undefined, just as they did before when there was no props to send down to them).
I must be missing something fundamental, I even tried all the component update or next state methods. Here is my component:
https://gist.github.com/geoffreysmith/ff909437a29ae8ab8db8038276b4f3b2
Thank you!
Edit: Here is my reducer:
import { combineReducers } from 'redux';
import { routerReducer as routing } from 'react-router-redux'
import { ADD_NEW_REPORT } from '../actions/Dashboard';
function reports(state = {}, action) {
switch (action.type) {
case ADD_NEW_REPORT:
return Object.assign({}, state, { [action.index]: addReport(undefined, action) })
default:
return state
}
}
function addReport(state, action) {
switch (action.type) {
case ADD_NEW_REPORT:
return {
index: action.index,
siteAddress: action.siteAddress,
receivedAt: action.receivedAt,
status: action.status
}
default:
return state
}
}
const rootReducer = combineReducers({
reports,
routing
})
export default rootReducer
Upvotes: 0
Views: 129
Reputation: 19203
I believe mapStateToProps
should return an object (the props
).
So I would change it to this:
const mapStateToProps = (state) => {
return {
reports: state.reports
}
}
Upvotes: 1