Skip to content
Advertisement

Getting custom components to work within react-hook-form using onChange

I have a checkout cart where you have different cart items, and for each one you can change the quantity prior to purchase.

Here’s how the code looks:

JavaScript

And the PureInput:

JavaScript

Everything works fine in terms of submitting the form. When I do, I get an array of whatever values I have entered into the input:

JavaScript

My package versions:

JavaScript

But my onChange no longer fires. How can I get the onChange to fire so I can log the value of the input inside <Checkout /> component?

Here’s a codesandbox if it helps

Advertisement

Answer

You can make the following changes to plug into onChange event

JavaScript

Hope it helps you in solving your problem,

Cheers

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement