Anyway to use Apollo Queries inside containers?
Jbern16 opened this issue · comments
Jbern16 commented
Anyway to integrate https://github.com/trojanowski/react-apollo-hooks into our containers?
Is something like this is possible? Which fires on an onChange hook?
const addExistingCreds = (() => {
const { data } = useQuery(CREDENTIALS_BY_EDORG, {
variables: {name: childEdOrg},
});
const existingCreds = data.allEducationalOrganizations[0].credentials;
return setCredential((prevCreds) => {
return update(prevCreds, { $set: existingCreds });
});
});
Jamie Kyle commented
Hooks can only be used at the top level of a component or another hook. See https://reactjs.org/docs/hooks-rules.html
But yes, you can call any hook inside of your container hook.
function useCurrentUser() {
let { data } = useQuery(...)
...
}
let CurrentUser = createContainer(useCurrentUser)
As for using a hook inside a callback: you can't. But I assume a graphql hook library would have a way of dealing with that
Jbern16 commented
Awesome, that helps. Think I can make this work. Thanks