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

React: Passing props to Component's inner function fails

I’m testing if it is possible to have a Button component which changes a ‘counter’ state, but the nature of the change depends on another state ‘type’. Doing console log of the prop ‘type’ inside the Button component it appears to get correctly the content of it, but when passing it to a inner funtion ‘handler’, it turns to ‘undefined’. Any idea of why this happens?

App.jsx

Button.jsx

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

Input.jsx

>Solution :

Should be

const handler = (type, setCounter) =>`
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