Skip to content

Using Callbacks ​

Field callbacks ​

When a field has a callback, there are three ways to choose what it receives:

  • field: 'path.to.nested.property' — a specific nested value.
  • field: 'path.to.nested.object' — a whole nested object.
  • No field — the whole row.
Three kinds of callback

Fetch data on demand ​

If the data comes from a server, use the fetch prop instead of data. The function runs when the user clicks and must return the rows to export. Pair it with before-generate and before-finish to show a loading state.

WARNING

fetch is only used when no data prop is set.

Fetch on click

A real API call looks like this:

js
async function fetchData() {
  const response = await fetch('/api/holidays?country=US&year=2017')
  const { holidays } = await response.json()
  return holidays
}

Released under the MIT License.