React-number-format: onValueChange with function

Created on 28 Jul 2020  路  3Comments  路  Source: s-yadav/react-number-format

I have a function that calculates the balance due, so onValueChange I put this function, but in the initial state of the component it executes the function.

I tried using onChange, but it doesn't have floatValues, sometimes it does and sometimes 'undefined'.

How could I perform the calculation function only when the user changes the value and not the initial state of react using formik?

enhancement

Most helpful comment

Hello, i have approximately the same problem. When the props value change the onValueChange is fired !! It creates infinite loop when an input update another input vice versa.

All 3 comments

Hello, i have approximately the same problem. When the props value change the onValueChange is fired !! It creates infinite loop when an input update another input vice versa.

+1 Have same problem.

Is the infinite loop issue still persist? A code snippet might help for this.

Plus we can start passing the source of onValueChange, whether it's caused by prop change or actual input change.

I think we can pass the source object as 2nd parameter to onValueChange. Something like.

{
   source: 'prop'|'event',
   event: eventObj, // only set when the source is event.
}
Was this page helpful?
0 / 5 - 0 ratings