gpt4 book ai didi

javascript - HTML onSubmit/onClick 处理函数可以有除事件之外的另一个参数吗?

转载 作者:行者123 更新时间:2023-12-04 09:33:58 26 4
gpt4 key购买 nike

<分区>

我遇到过一些情况 onClickonSubmit 函数同时需要 eventparameter。我可以在 React 或 vanilla html 标签中使用它吗?

或者,只是使用其他函数做一些副作用?


const CustomFC = ({}) => {
const [ id, setId] = useState("");
const [password, setPassword] = useState("");

type FormParams = {
id: string;
password: string;
}
const customClickHandler = useCallback((params: FormParams) =>
{
dispatch(params);
}, [id, password]);

const onChangeId = useCallback((id) => setId(id),[]);
const onChangePassword = useCallback((password) => setPassword(password),[]);

<Form
onClick ={customClickHandler}
onChange={{onChangeId, onChangePassword}}
/>
}

// Form.tsx
const Form = ({
onSubmit,
onChange,
}) => {
const { onChangeId, onChangePassword } = onChange;
const handleSubmit = ( e, params ) => { // <- can this be possible?
e.preventDefault();
onSubmit(params);
}
return (
<form onSubmit={handleSubmit}>
<input ... />
<input ... />
</form>
)
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com