Last active
April 15, 2021 19:42
-
-
Save ondrek/e944b25ca4e13a1c67f2031f61a91270 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// hook file | |
function Hook() { | |
const [ value, setValue ] = useState(null) | |
return { | |
secret: { | |
value, | |
fetch: (params) => post("/url", params).then(setValue) | |
} | |
} | |
} | |
// react component | |
function Element { | |
const { secret } = useInterface() | |
function fetchSecret() { | |
secret.fetch({ parameter: 123 }) | |
} | |
console.info(secret.value) | |
} |
This file contains hidden or 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
// api file | |
export function postToSecret(params) { | |
return post("/url", params) | |
} | |
// react component | |
function Element { | |
const [ value, setValue ] = useState(null) | |
function fetchSecret() { | |
postToSecret({ parameter: 123 }).then(setValue) | |
} | |
console.info(value) | |
} |
Author
ondrek
commented
Apr 15, 2021
const abc = useApi.accounts.fetch()
{ isPending || data }
const useQuery = (entity) => {
const [data, setData] = useState();
fetch(entity).then((x) => setData(x))
return { data }
}
useApi() {
return {
account: useQuery(entity)
}}
const {data} = useApi().account.fetch()
// hook
const account = (params) => {
const [ data, setData ] = useState()
post("/posts/create", params).then(x => setData(x))
return { data }
}
function useWorkspaceCheck(): Hook {
return {
account
}
}
// component
function onButtonClicked() {
const abc = account({ param: 124 })
console.info(abc)
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment