use_mutation

Function use_mutation 

Source
pub fn use_mutation<'a, Args, T, E, F, R, Success>(
    cx: Scope<'a>,
    mutator: F,
    on_success: Success,
) -> Mutation<'a, T, E, Args>
where F: Fn(Args) -> R + 'a, R: Future<Output = Result<T, E>>, Success: Fn(Rc<QueryClient>, Rc<T>) + 'a,
Expand description

Use a mutation that updates data on the server.

§Parameters

  • cx - The scope for the component the mutation is in.
  • mutator - The function that actually executes the mutation on the server. This can take in any type of arguments.
  • on_success - Function to execute when the mutation is successful. Used to invalidate queries or update queries with data returned by the mutation.

§Returns

A Mutation struct.

§Example

let Mutation { data, status, mutate } = use_mutation(
    cx,
    |name: String| async { Result::<_, ()>::Ok(name) },
    |client, data| client.set_query_data("name", data)
);