Toolforge Docs
DocsIO Primitivesloader

loader

Creates a loader instance to show a loading state to the user.

Usage

Loader

const loader = await io
  .loader({
    title: 'Processing',
    description: 'Please wait while we process your request...',
  })
  .start()

try {
  await performLongRunningTask()
} finally {
  await loader.stop()
}

Props

PropDescriptionTypeRequiredDefault
titleTitle of the loading operationstringYes
descriptionOptional description of the loading operationstringNoundefined

Returns

Returns a Loader instance with start() and stop() methods. Both methods are async and return the loader instance for chaining.

Examples

Basic loader usage

const loader = await io
  .loader({
    title: 'Uploading Files',
    description: 'Upload in progress...',
  })
  .start()

try {
  await uploadFiles()
  await loader.stop()
} catch (error) {
  await loader.stop()
  throw error
}

Separate start and stop

const loader = io.loader({
  title: 'Processing Data',
  description: 'This may take a while...',
})

// Start the loader explicitly
await loader.start()

try {
  await processData()
} finally {
  // Always stop the loader, even if an error occurs
  await loader.stop()
}

On this page