Continuing on from a previous SO thread involving the conversions from a class component to a functional component, I am now having issues with both the reset
and clear
button operations and unsure how to fix.
When clicking on both these buttons, I am getting the error:
TypeError Cannot read properties of undefined (reading 'settings')
My codebase can be found here
CodePudding user response:
The issues is you have replaced the whole state object with tree
value. So you need to spread state
and then set the tree
value in it. like this ...state
, please check following code:
const resetValue = () => {
setState({
...state,
tree: initTree
});
};
const clearValue = () => {
setState({
...state,
tree: loadTree(emptyInitValue)
});
};