DEV Community

Raj
Raj

Posted on

2 2

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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (1)

Collapse
 
krisrajzlive profile image
Raj

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay