modih65067
modih65067

Reputation: 129

Return data from React Function

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.

Upvotes: 0

Views: 533

Answers (3)

Thamothara Kannan
Thamothara Kannan

Reputation: 11

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

Upvotes: 1

cedx
cedx

Reputation: 36

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) {...}

Upvotes: 1

Ankit Saxena
Ankit Saxena

Reputation: 1207

There are a few ways to do it.

Upvotes: 1

Related Questions