简体   繁体   中英

how to submit form this Onchange? reactjs

how to submit form this Onchange? I don't have a button to fire the form, how to do that? I can't insert routes as it's a component for several clients. I use react hook forms

const handleChange = (e: any) => {
        const avatar = URL.createObjectURL(e.target.files[0])
        setAvatar(avatar)
      };

Did you try this solution using useEffect

 const [avatar,setAvatar] = useState(null); useEffect(() => { if(avatar) handleSubmit(); }, [avatar]); const handleChange = (e: any) => { const avatar = URL.createObjectURL(e.target.files[0]) setAvatar(avatar) }; // suppose that this is this is your handleSubmit function const handleSubmit = () => { // your code goes here };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM