Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError issue when converting a class component to a functional component

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’)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My codebase can be found here

>Solution :

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)
    });
  };
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading