'how to reset input fild without empty string in react.js

How can I reset the input field if I use it this way?

const [email, setEmail] = useState({ email: "", emailError: "" });
   
    const handleEmail = (inputEmail) => {
    if (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(inputEmail)) {
      setEmail({ email: inputEmail, emailError: "" });
    } else {
      setEmail({ email: "", emailError: "Invalid Email" });
    }
  };

   <Form.Control type="email"  onChange={(e) => handleEmail(e.target.value)} name="email" 
    placeholder="Enter email" />


Solution 1:[1]

You can use initial state variable, this is one of the best approach to reset states in react. If you want to reset seperately then you can give initial values for email and emailError instead of giving whole initial object

const initialState = {
    email: "",
    emailError: ""
}

const [email, setEmail] = useState(initialState);
    
const reset = () => {
  setEmail(initialState)
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Evren