Home > Software design >  Return data from React Function
Return data from React Function

Time:03-08

For example I have an field that needs to have an user selected, so I have another React component where I select there the value, so I have a state there, how can I send that data to the current Component I have.

CodePudding user response:

There are a few ways to do it.

CodePudding user response:

You can pass the value of that state as a prop:

const [selectedUser, setSelectedUser] = useState();
...
return (
  <OtherComponent prop={selectedUser} />
)

and receive that prop on the other component

export default function AnotherComponent(prop) {...}

CodePudding user response:

  1. use props in share data between componet 2).use redux
  • Related