react-credit-cards icon indicating copy to clipboard operation
react-credit-cards copied to clipboard

TypeError: Cannot read properties of undefined (reading 'replace')

Open tcetin opened this issue 3 years ago • 3 comments

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.

tcetin avatar Sep 21 '21 19:09 tcetin

me too aff

ederross avatar Jul 12 '22 23:07 ederross

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!

edu2105 avatar Oct 30 '22 22:10 edu2105

{ "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ "config:base" ] }

NEGANHUB avatar Nov 23 '22 03:11 NEGANHUB