-
-
Notifications
You must be signed in to change notification settings - Fork 5.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
[RFR] Add useEditController hook #3398
Conversation
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.
Awesome!
|
||
useEffect(() => { | ||
dispatch(resetForm(REDUX_FORM_NAME)); | ||
}, [resource, id, version]); // eslint-disable-line react-hooks/exhaustive-deps |
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.
You should pass the missing deps
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.
No, because the previous code was:
componentWillReceiveProps(nextProps: Props & EnhancedProps) {
if (
this.props.id !== nextProps.id ||
nextProps.version !== this.props.version
) {
this.props.resetForm(REDUX_FORM_NAME);
this.updateData(nextProps.resource, nextProps.id);
}
}
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.
I fail to see how it relates to the new hook version and to what hooks actually requires
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.
Just read this from an article by Dan:
You may omit dispatch, setState, and useRef container values from the deps because React guarantees them to be static. But it also doesn’t hurt to specify them.)
https://overreacted.io/a-complete-guide-to-useeffect/
Maybe it's true for react-redux dispatch
as well
Removes one level of indentation in the React tree for Edit views.
I also introduced a new specialized mutation hook,
useUpdate
. This addresses #2952 for thecrudUpdate
action.The only difference between
useEditController
andEditController
is that the former doesn't injecttranslate
(just like foruseListController
).