[Solved] How can i change state using setState from inside a function component when setState is declared outside of it. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

[Solved] How can i change state using setState from inside a function component when setState is declared outside of it.

https://code.sololearn.com/WP99GA8yDcg5/?ref=app

2nd Aug 2020, 11:24 AM
Abhay
Abhay - avatar
2 Answers
+ 3
You have to pass the setState function to Image_Component as a property. return (<Image_Component setState={setState} />); function Image_Component(props) { props.setState(true); }
2nd Aug 2020, 11:27 AM
Schindlabua
Schindlabua - avatar
+ 2
Thanks a lot Schindlabua
2nd Aug 2020, 11:29 AM
Abhay
Abhay - avatar