简体   繁体   English

如何提交这个 Onchange 表格? reactjs

[英]how to submit form this Onchange? reactjs

how to submit form this Onchange?如何提交这个 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我使用反应钩 forms

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

Did you try this solution using useEffect您是否使用 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 };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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