fangmd / blogsource

6 stars 0 forks source link

good code #90

Open fangmd opened 1 year ago

fangmd commented 1 year ago

react 表单简化


  const [userInfo, setUserInfo] = useState({
    username: "",
    age: "",
    gender: "",
    email: "",
    password: "",
    address: "",
    city: ""
  });

  const onChange = (e) => {
    setUserInfo((pre) => ({ ...pre, [e.target.name]: e.target.value }));
  };

  <input type="text" name="age" placeholder="age" onChange={onChange} />