-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
47 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as useCms } from "./useCms"; | ||
export { default as useQuery } from "./useQuery"; | ||
export { default as useMutation } from "./useMutation"; |
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,13 @@ | ||
import { useContext } from "react"; | ||
import { CmsContext } from "@webiny/app-headless-cms/admin/contexts/Cms"; | ||
|
||
const useCms = () => { | ||
const context = useContext<any>(CmsContext); | ||
if (!context) { | ||
throw new Error("useCms must be used within a CmsProvider"); | ||
} | ||
|
||
return context; | ||
}; | ||
|
||
export default useCms; |
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,15 @@ | ||
import useCms from "./useCms"; | ||
import { useMutation as apolloUseMutation } from "react-apollo"; | ||
|
||
const useMutation = function(mutation, options = {}) { | ||
const { | ||
environments: { apolloClient } | ||
} = useCms(); | ||
|
||
return apolloUseMutation(mutation, { | ||
client: apolloClient, | ||
...options | ||
}); | ||
}; | ||
|
||
export default useMutation; |
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,16 @@ | ||
import useCms from "./useCms"; | ||
import { useQuery as apolloUseQuery } from "react-apollo"; | ||
|
||
const useQuery = function(query, options = {}) { | ||
const { | ||
environments: { apolloClient } | ||
} = useCms(); | ||
|
||
return apolloUseQuery(query, { | ||
client: apolloClient, | ||
skip: !apolloClient, | ||
...options | ||
}); | ||
}; | ||
|
||
export default useQuery; |