Skip to content
This repository has been archived by the owner on Aug 23, 2021. It is now read-only.

Add deps to useGraphqlForms #185

Open
logan-anderson opened this issue May 7, 2021 · 1 comment
Open

Add deps to useGraphqlForms #185

logan-anderson opened this issue May 7, 2021 · 1 comment

Comments

@logan-anderson
Copy link
Contributor

logan-anderson commented May 7, 2021

It would be nice if we could have some outside control other then the query string to cause the hook to be re-run.

Basic idea

 const [payload, isLoading] = useGraphqlForms({
    query: (gql) => gql(query),
    variables: props.variables || {},
    deps: [thingOne, thingTwo]
  });

or maybe

 const [payload, isLoading] = useGraphqlForms({
    query: (gql) => gql(query),
    variables: props.variables || {},
  }, [thingOne, thingTwo]);

When thing one or thing two is updated then the hook will re-run.

This was my (bad) temporary work around

 const [payload, isLoading] = useGraphqlForms({
    query: (gql) => gql(`#${JSON.stringify(thingOne)} ${query}),
    variables: props.variables || {},
  });
@jeffsee55
Copy link
Member

jeffsee55 commented Jun 21, 2021

I think the proper way to handle this is internally, at least as a first stab. If something that we return from the hook is stale it's because something they gave us has changed, so it's our responsibility to implement that in the hook itself.

Specific example, when the branch changes on the Tina client, we should reset everything. This api:

 const [payload, isLoading] = useGraphqlForms({
    query: (gql) => gql(query),
    variables: props.variables || {},
  }, [someBranchState]);

Feels like we're passing that off to the user too much. I feel like if we do support a dependencies argument it would have to be for more one-off use cases a developer might need - so in saying that, I'd like to get more examples of when that would be.

EDIT: I've created an issue for this specific example #278

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants