P粉7446912052023-08-28 00:00:43
In terms of good coding practices, you should avoid putting too much business logic in JSX. Just extract your onClick
handler outside of JSX.
Secondly, you don't want to return to saveForm
after deshaking. Instead call it. So replace () => saveForm
with saveForm
.
function saveForm() { //在这里执行操作 } const debouncedClickHandler = debounce(saveForm, 1500, {maxWait: 2000}) <Button onClick={debouncedClickHandler}>保存</Button>
You can also use the useCallback
hook. I leave the best practices for using useCallback
hooks up to you to explore if needed.