Search code examples
reactjsfirebaseauthenticationreact-props

Reactjs setEmail is not a function onChange although it is function


It gives an error i do not know why, If you look my codes, there is not any problem you will see. Login Route page:

    const [email, setEmail] = useState("");
    
    <LoginPage
              email={email}
              setEmail={setEmail} />

Login Form codes:

    const {
        email,
        setEmail,
      } = props;
    
    <input
                    type="email"
                    className="form-control"
                    placeholder="Enter email"
                    value={email}
                    onChange={(e) => setEmail(e.target.value)}
                  />

Solution

  • Login Page Component <LoginPage />

    Login Form Component

    import React, { useState } from "react";
    
    const LoginForm = (props) => {
      const [email, setEmail] = useState("");
      return (
        <>
          <input
            type="email"
            className="form-control"
            placeholder="Enter email"
            value={email}
            onChange={(e) => setEmail(e.target.value)}
          />
          {/* Other components */}
        </>
      );
    };