How to use the swr.trigger 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('')
  }

swr

React Hooks library for remote data fetching

MIT
Latest version published 3 months ago

Package Health Score

98 / 100
Full package analysis