DEV Community

loading...

react state lost

krisrajzlive profile image Raj ・1 min read
Here's the state data structure:
projectData:
{
        projectCode: '',
        projectName: '',
        projectDescription: '',
        clientCode: '',
        clientName: '',
        officeCode: '',
        office: '',
        industryTypeName: '',
        statusName: '',
        statusCode: '',
        projectResources: []
}
Enter fullscreen mode Exit fullscreen mode

Here's the reducer, when this gets executed all the state data is lost except projectResources

case "SET_PROJECTROLE":
            {
                const newResources = [...state.projectData.projectResources];
                newResources[action.payload.Index].ProjectRole = action.payload.ProjectRole;
                return {
                    ...state,
                    projectData:
                    {
                        ...state.projecData,
                        projectResources: [...newResources]
                    }
                };
            }
Enter fullscreen mode Exit fullscreen mode

Discussion (2)

pic
Editor guide
Collapse
3in0 profile image
3in0

typo at ...state.projecData

Collapse
krisrajzlive profile image
Raj Author

Gosh! you saved me!! :) thanks @3in0