react-credit-cards
react-credit-cards copied to clipboard
TypeError: Cannot read properties of undefined (reading 'replace')
I am getting this error in functional component.
TypeError: Cannot read properties of undefined (reading 'replace')
Can you look at please this error.
Is there any restriction to use functional or class based component.
me too aff
I was able to make it work using functional component. Instead of updating the state with an object of only one field as in the handleInputFocus and handleInputChange functions, spread your current state to get all the data and then add the new field.
This is what I have:
const [cardData, setCardData] = useState({
cvc: '',
expiry: '',
focus: '',
name: '',
number: ''
});
const handleInputFocus = (e) => {
setCardData({
...cardData,
focus: e.target.name
});
}
const handleInputChange = (e) => {
const { name, value } = e.target;
setCardData({
...cardData,
[name] : value
});
}
Hope it also works for you!
{ "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ "config:base" ] }