How to use event handler properly
See original GitHub issueHi, I’m sure this is a problem with my understanding, but I can’t figure out how to properly handle a change to the NumberFormat component (basically how to use my handler). I’m completely new to Reactjs, please play nicely with me 😃
The below works fine with an component: ` return ( <fieldset> <legend> Enter Phone Number </legend> <ValueField number={this.props.number} /> </fieldset> );
` But I can’t figure out how to do the same with the <NumberFormat> component:
return ( <fieldset> <legend> Enter Phone Number </legend> <NumberFormat isNumericString={true} format="(###) ###-####" mask=" " value={this.props.number} onValueChange={(values, e) => { const {formattedValue, value} = values; {handleChange(value)} } } /> <ValueField number={this.props.number} /> </fieldset> );
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (5 by maintainers)
You were using this function:
onValueChange={(values, e) => this.handleChange(values, e)}
To call this function:handleChange(e) { this.props.onNumberChange(e.target.value); }
As you can see the arguments do not line up. You are giving handleChange 2 arguments. As written, you are only using the first one ‘values’, but you are trying to read it as ‘e’ and event.
Here is a working version:
Thanks for your help. I managed the custom format function. Here’s the final product if you’re interested.
https://gist.github.com/thewholuver94/ef43d718bf4e83104d08b46676d35756