小编jot*_*roo的帖子

Onchange in React input causes the input to rerender on every letter

因此,我在两个函数中创建了输入,并在Onchange其上获取输入到其中的值。但每当我在输入中输入内容时,我一次只能输入一个字母,然后它就会失去焦点,我相信这是因为组件继续渲染。我还意识到,每当我删除 Onchange 和 value 属性时,一切都会恢复正常,我可以轻松地输入所有内容。我该如何解决这个问题?

应用程序.js

import style from "./auth.module.css";
import { useEffect, useRef, useState } from "react";
import { useAuthState } from 'react-firebase-hooks/auth';
import { auth, signInWithEmailAndPassword, signInWithGoogle, registerWithEmailAndPassword } from "../../firebase";
import { CSSTransition } from "react-transition-group";


function Auth() {
  const [activeMenu, setActiveMenu] = useState("main");
  const [email, setEmail] = useState('');
  const [password, setPassword] = useState('');
  const [user, loading, error] = useAuthState(auth);

  const Emailform = () => {
    return (
      <div className={style.formBox}>
        <label className={style.label}>Email:</label>
        <form className={style.input}>
          <input …
Run Code Online (Sandbox Code Playgroud)

reactjs

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

reactjs ×1