Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于使用useRef解决闭包陷阱的问题 #1

Open
mayu888 opened this issue Jun 3, 2020 · 1 comment
Open

关于使用useRef解决闭包陷阱的问题 #1

mayu888 opened this issue Jun 3, 2020 · 1 comment

Comments

@mayu888
Copy link

mayu888 commented Jun 3, 2020

onChange={(value) => onCheckedChangeRef.current(cartItem, value)},onChange事件必须用一个函数包裹住传进来的onCheckedChangeRef.current函数,虽说在你这个场景中这样做合适,但是若有场景onChange={onCheckedChangeRef.current}就无法实现

@aaronlam
Copy link

aaronlam commented Feb 6, 2021

onChange={(value) => onCheckedChangeRef.current(cartItem, value)},onChange事件必须用一个函数包裹住传进来的onCheckedChangeRef.current函数,虽说在你这个场景中这样做合适,但是若有场景onChange={onCheckedChangeRef.current}就无法实现

其实也没差吧,都是一样的。你不包裹直接把 onCheckedChangeRef.current 当作 onChange 的回调当然也可以,那就没办法传入 cartItem 而已。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants