threlte logo
@threlte/extras

onSuspend

onSuspend invokes a callback when the component becomes suspended within the boundaries of a <Suspense> component. If there is no <Suspense> component, the callback will never be executed, as the component will never suspend.

Example

The following component loads a model with the hook useGltf and is potentially wrapped in a <Suspense> boundary.

<script>
  import { T } from '@threlte/core'
  import { onSuspend, useGltf } from '@threlte/extras'

  const gltf = useGltf('model.gltf')

  onSuspend(() => {
    console.log('The component has been suspended')
  })
</script>

{#await gltf then { scene }}
  <T is={scene}>
{/await}

onSuspend can be used to execute additional logic when a component becomes suspended within a <Suspense> boundary.