+ 1

Can I transfer a state item in react from first component to second component!

12th May 2019, 10:39 AM
CodeFu
CodeFu - avatar
10 Answers
+ 7
I don't have a proper way to do that but what strikes on my mind is : When you render second component you can pass that state item as prop. That's not the best way I know. CalviŐ˛ can help maybe.
12th May 2019, 10:45 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 5
Here a simple sample of passing a state from parent to children component through attribute props in React Hooks. https://code.sololearn.com/W5do6CUTXXq1/?ref=app
13th May 2019, 4:35 AM
CalviŐ˛
CalviŐ˛ - avatar
+ 4
Yes mate. Let me try it.
12th May 2019, 3:51 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 3
Thanks for suggestion Raj Chhatrala!
12th May 2019, 10:46 AM
CodeFu
CodeFu - avatar
+ 3
You can pass state from parent to child. Or the opposite way : from child to parent. https://dev.to/zeyadetman/how-to-pass-state-between-components-in-reactjs-2pg1 If not ancestor-descendant, route via App.
13th May 2019, 1:39 AM
Gordon
Gordon - avatar
+ 2
Raj can you give me example!
12th May 2019, 3:29 PM
CodeFu
CodeFu - avatar
+ 2
Thanks!
12th May 2019, 3:54 PM
CodeFu
CodeFu - avatar
13th May 2019, 11:07 AM
CodeFu
CodeFu - avatar
+ 1
What is the problem!?
14th May 2019, 10:51 AM
CodeFu
CodeFu - avatar
0
🇲🇰Maksi - Vik🇲🇰 your code has syntax error, cannot run.
14th May 2019, 2:58 AM
CalviŐ˛
CalviŐ˛ - avatar