reactjsarraysobjectdestructuring

Exporting uesState variable into another component/page


I'm a bit stuck. I've put the users input results into an array that can be used on another component. However when I try to destructure the 'newList' in another component/page it doesn't show anything or it returns [Object object] when I console.log it.

This is where the data is put into an array


Solution

  • Firstly, in the formSubmit function - you would want to spread the input in the newList array as well, or else it would be something like

    [[{}, {}], {},{}]
    

    So, in order to have a correct list, spread the input as below:

     newList =[...input, ...userEnquiry]
        setUserEnquiry(newList)