I want to set the state to its previous value. I have a list of checkboxes and based on it selections and click of "Apply" the columns in the table gets shown/hidden. I am able to achieve this functionality. But on click on "Cancel" , I am not able to set it to previous state.
CodeSandbox: https://codesandbox.io/s/funny-browser-2z3s5
On click of Cancel, the checkboxes should be set to previous state.
Click is handled with a function in SelectComponent.tsx, the goal is to reset optionsArr to its original value:
cancelSelection = (event: any) => {
this.setState({ showList: false });
this.setState((prevState: any) => ({
// Isn't working
optionsArr: prevState.optionsArr
}));
};