DEV Community

Raj
Raj

Posted on

react state lost

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

Top comments (1)

Collapse
 
krisrajzlive profile image
Raj

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