search

Home  >  Q&A  >  body text

Export useState variable to another component/page

I'm a little stuck. I have put the user input results into an array that can be used on another component. However, when I try to deconstruct "newList" in another component/page, it doesn't display anything or when I console.log it returns [Object object].

This is where the data is put into the array

P粉311423594P粉311423594261 days ago461

reply all(1)I'll reply

  • P粉133321839

    P粉1333218392024-04-06 10:49:01

    First, in the formSubmit function - you also want to propagate the input into the newList array, otherwise it will look like

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

    So, to get the correct list, propagate the input as follows:

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

    reply
    0
  • Cancelreply