didact
didact copied to clipboard
Add useEffect hook
Hi again :)
Here is an attempt at implementing useEffect. It seems to work, but it might be closer to useLayoutEffect since I run the effect right after updating the dom...
Anyway I would be happy to know what you think of this, and how you would have implemented it
Seems like the cleanup is never run.
Hello! The error is in the cancelEffect function, because when the cleanup is added in runEffects, we are updating it to the current version of Fiber, but on the next commit it is converted to the previous version. So, what we must do in cancelEffects is to add in the condition if it has hooks in its old version (fiber.alternate.hooks), then filter the hooks of the old version (fiber.alternate.hooks) and finally execute the cleanups. I hope I've helped ✌
Hey has anyone used the useState inside this hook? doesnt seem to be working for me
Hey has anyone used the useState inside this hook? doesnt seem to be working for me
You need to pass wipFiber
to runEffects
and cancelEffects
instead of fiber
runEffects(fiber)
-> runEffects(wipFiber)
@gvergnaud , it's working on my side after replace simply fiber
with wipFiber
.
thank you for your effort.
This will not work anymore if you use another useState
below the useEffect
hook, because you will get a mismatch between effect and state hooks in the update procedure of the useState
. You will also need to tag the state hooks and filter for the state hooks during the update.