Hello everyone, I may need some of your front-end expertise on this one.
I'm building a form with different inputs and a button.
The inputs are custom React components. As shown in the picture.
And I am trying to handle state in the corresponding parent component without any 3rd party library.
My attempt to handle state in custom React input components failed with the error in the picture (Unhandled Runtime Error
TypeError: onEdit is not a function).
Does any one know what I'm doing wrong.
8 Replies
Well the problem isn't the type
Can you show where you actually passed this onEdit
Typescript doesn't throw runtime errors
So it's basically saying, there's no onEdit being passed, something is going wrong there
onEdit is passed as a prop in a parent component
don't pass a callback to a callback
just put
onChange={onEdit}
see if it worksit triggers a type error. Plus I need to pass the event object to the onEdit function
here's how I handle state changes in parent components without any fancier state management, Suppose I have an input component as so :
and in the parent
Thank you so much.
I just needed to change the onEdit prop type and call it directly without using a callback just like the way you implemented it.
no problem 👋