Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

passing props form child to parent component in react

return
 <div>
    <RadioOptions />
    <GenButton />
    <OutputPass />
 </div>

I recently worked on my side-project and I found an issue in my code. inRadiooptions  I used some useState hooks, and I want to pass that state from Radiooptions component to its parent(passGen) and then from there, pass that state toGet Button component to check some condition and if nothings wrong, generate the password. (I’ll also attach my GitHub repo for better access to my source code)

https://github.com/arviinmo/palora/tree/main/components/passwordgenerator

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can’t pass props from child to parent in React, it’s only one way (from parent to child).

You should either:

  • Put the state in the parent component and manipulate it from the child component by passing the setter function in the props
  • Use something like Redux Toolkit to create a global state that all components can have access to
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading