Reputation: 596
I'm having problem with React-Redux, I want to update specific values in my store, but instead I'm getting new object in my store.
My action type:
export const SENDMESSAGE = "SENDMESSAGE";
My action creator:
export const updateContactFormData = (payload) => ({
type: SENDMESSAGE,
payload: payload
})
My initial state:
export const formInitialData = {
formShape: {...},
formData: {...},
formContactData: {
name: '',
email: '',
text: ''
}
}
And my reducer looking like this:
export default function formReducer(storeData, action) {
switch(action.type) {
case SENDMESSAGE:
return {
...storeData,
[storeData.formContactData]: action.payload,
}
default:
return storeData || formInitialData
}
}
And now im getting new object in my store, as the Redux tool show: enter image description here
Upvotes: 0
Views: 87
Reputation: 45121
You want update property value, not to define a new property using previous value as a name.
return {
...storeData,
formContactData: {...storeData.formContactData, ...action.payload},
}
Upvotes: 1