question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return data from mutate

See original GitHub issue

Now that mutate support passing an async function to get the data it will be helpful to get that data as return value of mutate.

const data = await mutate('/api/data', fetch('/api/data').then(res => res.json()))
// use data

This way if I want to use the data right now for something else I don’t need to use the old way of first fetch and await and then pass the data to mutate and return it below.

const data = await fetch('/api/data').then(res => res.json());
mutate('/api/data', data)
// use data

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
BrunoQuaresmacommented, Nov 29, 2019

I think would be nice to have this interface as well:

mutate(key, data => { ...data, [newId]: newData })
2reactions
sergiodxacommented, Feb 3, 2020

Yeah, you should be able to mutate any key used in your app even if you don’t have the current data in the scope of your mutate call.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mutations in Apollo Client - Apollo GraphQL Docs
An array (or a function that returns an array) that specifies which queries you want to refetch after the mutation occurs. Each array...
Read more >
How do you get the return data from a mutation? #194 - GitHub
I see no way to get what the server has sent back after making a mutation.
Read more >
Return Values and Object Mutations - Practical Data Science
But when we mutate an object, the newly mutated object won't be returned to us. Instead, the method will return either nothing (...
Read more >
Mutation & Revalidation - SWR
mutate returns the results the data parameter has been resolved. The function passed to mutate will return an updated data which is used...
Read more >
Create, modify, and delete columns — mutate • dplyr
Value · Columns from .data will be preserved according to the .keep argument. · Existing columns that are modified by ... will always...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found