-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3181 from marmelab/data-hooks
[BC Break] [RFR] Data hooks
- Loading branch information
Showing
25 changed files
with
1,013 additions
and
828 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { FunctionComponent, ReactElement } from 'react'; | ||
import useMutation from './useMutation'; | ||
|
||
type DataProviderCallback = ( | ||
type: string, | ||
resource: string, | ||
payload?: any, | ||
options?: any | ||
) => Promise<any>; | ||
|
||
interface ChildrenFuncParams { | ||
data?: any; | ||
loading: boolean; | ||
error?: any; | ||
} | ||
|
||
interface Props { | ||
children: ( | ||
mutate: () => void, | ||
params: ChildrenFuncParams | ||
) => ReactElement<any, any>; | ||
type: string; | ||
resource: string; | ||
payload?: any; | ||
options?: any; | ||
} | ||
|
||
/** | ||
* Craft a callback to fetch the data provider and pass it to a child function | ||
* | ||
* @example | ||
* | ||
* const ApproveButton = ({ record }) => ( | ||
* <Mutation | ||
* type="UPDATE" | ||
* resource="comments" | ||
* payload={{ id: record.id, data: { isApproved: true } }} | ||
* > | ||
* {(approve) => ( | ||
* <FlatButton label="Approve" onClick={approve} /> | ||
* )} | ||
* </Mutation> | ||
* ); | ||
*/ | ||
const Mutation: FunctionComponent<Props> = ({ | ||
children, | ||
type, | ||
resource, | ||
payload, | ||
options, | ||
}) => children(...useMutation(type, resource, payload, options)); | ||
|
||
export default Mutation; |
Oops, something went wrong.