-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Update the block component to use react hooks instead #14985
Conversation
This is a good start. Making this code more straightforward is going to help always keeping a cleaner state for any future iterations. There's another motivation for making use of hooks here which is getting some more concrete awareness of how they can later benefit the consumable block API (exposing some of what has been so far absorbed in |
8f72942
to
f33e227
Compare
I run the performance tests to compare this branch against master and noticed similar times. This refactor has no impact on performance. Can I get a review here, I'm thinking of merging this as is and try other smaller improvements using hooks separately. |
79f7a6e
to
453dc59
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit difficult to review, but it appears in good shape. I like how hooks help to consolidate where previously we have disjointedness of checking for changes in props values between componentDidMount
, componentDidUpdate
.
The issue with the ESLint warning should probably be resolved. There's also a merge conflict.
453dc59
to
9fd8640
Compare
@Tug , can you give this PR a quick look to see if it can affect the native mobile in any way? cc @youknowriad |
62ad155
to
709cf53
Compare
@hypest afaics it's only touching |
@@ -26,6 +26,5 @@ module.exports = { | |||
'react/prop-types': 'off', | |||
'react/react-in-jsx-scope': 'off', | |||
'react-hooks/rules-of-hooks': 'error', | |||
'react-hooks/exhaustive-deps': 'warn', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why this was removed? Looking back through the history to #14995 (comment), I see there was some initial uncertainty about the rule. But as I've been reading more about it, it seems like one of those things where it should be a safe default to use, and that most problems end up from mis-use (related discussion). What are these valid exceptions we have, and are they really the majority of cases that we shouldn't only be opting-out as opposed to disabling this rule altogether?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I first started trying hooks, it felt that we had a too many exceptions. Maybe related to the way our components were written or related to my thought process when writing components. happy to reconsider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Truthfully, I'm still trying to understand all that the rule is meant to cover (its documentation... doesn't exist), but the general tone of the discussion around it from their end seems to be that if a developer is fighting with the rule, there's a higher likelihood the developer is "doing it wrong", so I'm curious to see a few specifics.
Maybe I'll turn on the rule locally to see what issues come up, in order to get a better understanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It:
- Forces you to pass
deps = []
. - Statically analyzes callbacks for closures and forces you to add them to
deps
.
I said previously that we're not going to refactor our components to use hooks just to use hooks. But in this PR, I'm trying to refactor the
BlockListBlock
component.The main reasons are:
At the moment, I kept the refactoring as minimal as I can, which means I kept, in theory, the same flows, states... There's something different though which can be impactful. A lot of the callbacks are not bound the instance object which means some child components might rerender more often. There are options and solutions but I want to measure the differences before making changes.
useCallback
to memoize these callbackswithDispatch
HoC instead.