Experiment how React hooks can improve our codebase#11161
Experiment how React hooks can improve our codebase#11161youknowriad wants to merge 1 commit intomasterfrom
Conversation
|
Nice to see that React 16.7 is passing all of our tests. There's a lot of warnings (deprecations) though :) |
2909ada to
ac01e2b
Compare
This is surprising (even if you subtract 2 lines added for React version upgrade). It definitely promotes code reuse and composition similar to what HOCs offer with much easier syntax. By easier, I mean no need to create all those wrapping components which do nothing and introduce lots of confusion. I'm looking forward to the day when 16.7 stable is out 💯 |
|
I think it matches our journey between render props, higher-order wrapping functions, and |
|
Closing, let's revisit once hooks are officially shipped. |
|
Psssssssssst, @youknowriad... They've officially shipped! 😊 |
|
Not quite yet, but hopefully very soon :) |
React 16.7 introduces this concept of hooks. In this PR, I'm creating some hooks to explore this API and how it can improve or not our codebase and APIs.
So far, I'm thinking that it's a great API, I like how you can reason about discrete behaviors and combine them later in components without having to wrap your components or create extra DOM nodes you don't really need.
useImageSizeto retrieve the image size and height,useElementSizeto retrieve the size of an element and refresh it if the window is resized.ImageWidthcomponent to combine the two hooks above instead of a complex component class.ImageWidthcomponent can be eliminated entirely (in favor of using the hooks directly in the image block) but I didn't want to push the refactor further.