How to use the react-query.setQueryData function in react-query

To help you get started, we’ve selected a few react-query examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tannerlinsley / react-query / examples / optimistic-updates / pages / index.js View on Github external
async function handleSubmit(event) {
    event.preventDefault()
    // mutate current data to optimistically update the UI
    // the fetch below could fail, so we need to revalidate
    // regardless

    setQueryData('todos', [...data, text], {
      shouldRefetch: false,
    })

    try {
      // send text to the API
      await mutatePostTodo(text)
      setText('')
    } catch (err) {
      console.error(err)
    }
  }
github wp-headless / fetch / packages / react / src / hooks / useFetch / index.js View on Github external
const update = attributes => {
    setQueryData(key, previous => ({ ...previous, ...attributes }), {
      shouldRefetch: false
    });
    return mutate(attributes, { updateQuery: key });
  };