How to use the swr.mutate function in swr

To help you get started, we’ve selected a few swr 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 zeit / swr / examples / optimistic-ui / 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, in that case the UI will
    // be in an incorrect state
    mutate('/api/data', [...data, text], false)
    // send text to the API
    await fetch('/api/data', {
      method: 'POST',
      body: JSON.stringify({ text })
    })
    // to revalidate the data and ensure is not incorrect
    // we trigger a revalidation of the data
    trigger('/api/data')
    setText('')
  }
github wp-headless / fetch / packages / react / src / hooks / useFetch / createFetcher.js View on Github external
destroy: attributes => {
      client.namespace(namespace).resource(resource);
      mutate(key, client.delete(id, attributes));
    }
  };
github zeit / swr / examples / local-state-sharing / pages / index.js View on Github external
onClick={() => {
          mutate("globalState", { ...data, name: value }, false)
        }}
      >
github wp-headless / fetch / packages / react / src / hooks / usePost / index.js View on Github external
update: async attributes => {
      client.namespace(namespace).resource(resource);
      await mutate(key, requestToResponse({ ...data, ...attributes }), false);
      fetch();
    }
  };
github wp-headless / fetch / packages / react / src / Fetch / index.js View on Github external
const update = attributes => {
    return mutate(
      key,
      client
        .namespace(namespace)
        .resource(resource)
        .update(key, attributes)
    );
  };
github wp-headless / fetch / packages / react / src / hooks / useFetch / createFetcher.js View on Github external
update: attributes => {
      client.namespace(namespace).resource(resource);
      mutate(key, client.update(id, attributes));
    },
    destroy: attributes => {

swr

React Hooks library for remote data fetching

MIT
Latest version published 3 months ago

Package Health Score

93 / 100
Full package analysis