-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: add useEventCallback() #6
base: master
Are you sure you want to change the base?
Conversation
Hi @exKAZUu , why did you change |
Hi @artem-malko If we use But, if we use ( Note So, I believe that the problem of How do you think? I just want to employ a better solution. Please let me know your thought! |
I thought, the main problem of useLayoutEffect is facebook/react#14099 (comment) And devs from react-redux have solved that problem with useIsomorphicLayoutEffect. And the last thing: calling from render: https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback There is a simple solution: const ref = useRef(() => {
throw new Error('Cannot call an event handler while rendering.');
}); As for me, usage of useImperativeHandle in a such context is quite strange and not obviously. May be it is because I am new to this concept (I mean useImperativeHandle). |
Thanks! Yeah, I just tested ypresto's example (facebook/react#14099 (comment)). |
@exKAZUu we need a If you will add const ref = useRef(() => {
throw new Error('Cannot call an event handler while rendering.');
}); to useLayoutEventCallback, you will see an error: https://codesandbox.io/s/react-useeventcallback-test-mblch So, it is not silently wrongly now) What do you think? |
Sorry, I missed your sample code 😓 I feel your are right. I will test some code including yours and reply. |
@exKAZUu cool) |
facebook/react#14099 (comment)
Using this function, the following TypeScript error will occur at
(0, ref.current)
.For now, change it to
ref.current(....args)
to avoid this error.