jamiebuilds / unstated-next

200 bytes to never think about React state management libraries ever again

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Anyway to use Apollo Queries inside containers?

Jbern16 opened this issue · comments

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 });
  });
});

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

Awesome, that helps. Think I can make this work. Thanks