Home made useObserver & HOC implementations... still works #3391
seivan
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I made a home baked implementation of
useObserver
andobserver
(HOC) a while ago to learn more about the internals.This was made like two years ago and some stuff have changed since then, however I am surprised to see it still working.
I was hoping someone could give their input on what it is actually missing compared to current
mobx-react-lite
useObserver
hook.forceUpdate
&useReaction
are extracted into their own snippets for sake of brevity.It still actually works.
One thing I noticed that it did better was in React Dev Tools, it shows both HOC being used, and not just
memo
That's used with the following HOC:
withObserver
(HOC)I extracted the code from
useObserver
hook here to make snippet easier to consume. They are inlined. I know you shouldn't call hooks inside functions, but it also works in case anyone was curious.The types are defined below.
I can't tell what the difference is now, but back then I recall that there was issues with React.FC having implicit children.
Also, I wanted to make sure primitive types were valid. Things might have changed since then, including React 18 allowing
undefined
as return type.Beta Was this translation helpful? Give feedback.
All reactions