Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tcetin opened this issue Sep 21, 2021 · 3 comments
Open

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

tcetin opened this issue Sep 21, 2021 · 3 comments

Comments

@tcetin
Copy link

tcetin commented Sep 21, 2021

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.

@ederross
Copy link

me too aff

@edu2105
Copy link

edu2105 commented Oct 30, 2022

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!

@NEGANHUB
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants