Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass mutation variables when calling executeMutation #103

Closed
baransu opened this issue Sep 22, 2019 · 4 comments
Closed

Pass mutation variables when calling executeMutation #103

baransu opened this issue Sep 22, 2019 · 4 comments

Comments

@baransu
Copy link
Contributor

baransu commented Sep 22, 2019

As shown in this example, mutation variables are passed when hook is created. https://github.com/FormidableLabs/reason-urql/blob/master/examples/3-mutation/src/Dog.re#L66

In my use case I want to create mutation hook at top of the component but pass variables later (for example from form submission callback function). Does reason-urql support it. I cannot find any documentation or example about such case.

let (_, executeSignInMutation) = Hooks.useMutation();

let form =
  Form.useForm(~onSubmit=(state, _) =>
    executeSignInMutation(
      ~request=
        Mutations.SignIn.make(
          ~email=state.email,
          ~password=state.password,
          (),
        ),
    )
    |> ignore
  );
@gugahoa
Copy link
Contributor

gugahoa commented Sep 22, 2019

You have to pass the variables during the request creation, and pass that to the hook. Here's an example: https://gist.github.com/gugahoa/b959b7d0b98b87cc1822b6754b85fa34

@baransu
Copy link
Contributor Author

baransu commented Sep 22, 2019

Thank you for the example. Could you show how its possible with reformality: https://github.com/MinimaHQ/re-formality/blob/master/README.md

It seems super inconvenient to handle it way you show because you have to define your hook earlier than callback where you don’t have the data yet if you don’t control your state manually.

@gugahoa
Copy link
Contributor

gugahoa commented Sep 22, 2019

@baransu
Copy link
Contributor Author

baransu commented Sep 23, 2019

That's what I was looking for. Thanks!

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

No branches or pull requests

2 participants