-
-
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] Declare fetch side effects as function #3425
Conversation
Switching to RFR |
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.
Shouldn't we update the upgrade guide too ?
@@ -35,7 +35,7 @@ const UserEditToolbar = props => { | |||
return ( | |||
<Toolbar {...props} classes={classes}> | |||
<SaveButton /> | |||
<DeleteWithConfirmButton /> | |||
<DeleteWithConfirmButton {...props} /> |
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.
We pass props to both the toolbar and the button ?
import { Identifier } from '../types'; | ||
|
||
/** | ||
* Get a callback to call the dataProvider with a DELETE verb, the result and the loading state. |
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.
the result ?
docs/Actions.md
Outdated
+ } | ||
); | ||
return <FlatButton label="Approve" onClick={approve} disabled={loading} />; | ||
}; | ||
``` | ||
|
||
React-admin can handle the following side effects: | ||
The `onSuccess` function is called with the response from the `dataProvider` as argument. The `onError` function is called wit hthe error returned by the `dataProvider`. |
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.
The `onSuccess` function is called with the response from the `dataProvider` as argument. The `onError` function is called wit hthe error returned by the `dataProvider`. | |
The `onSuccess` function is called with the response from the `dataProvider` as argument. The `onError` function is called with the error returned by the `dataProvider`. |
I don't think we need to add anything to the upgrade guide, as this adds only backward compatible changes. Any application running before that PR will continue to run after that PR. |
This is totally backwards compatible - delerative side effect objects are still interpreted by the Redux saga.
useNotify
,useRedirect
,useRefresh
, anduseUnselectAll
hooksuseDataProvider
to executeonSuccess
andonFailure
functions in the context of a hookCloses #3413.
This change does not reduce the code in controllers, but makes it more understandable. There are less moving parts, it's more idiomatic to modern React, and it bypasses some of the redux-saga logic.
It allows to customize side effects quite easily, e.g. to display a custom notification message in case of failed HTTP request.
This also opens the path for a pure hook-based fetch side effect handling (not using the fetch saga anymore).