Home > Software engineering >  React: Passing props to Component's inner function fails
React: Passing props to Component's inner function fails

Time:10-24

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

Input.jsx

CodePudding user response:

Should be

const handler = (type, setCounter) =>`
  • Related