GuobaGuoba Utils

useMount

@guoba-ai/hook / useMount

Function: useMount()

function useMount(fn): void;

Defined in: useMount.ts:25

Run a callback once when the component mounts.

Parameters

fn

() => void

The callback to run on mount

Returns

void

Example

useMount(() => {
  console.log('Component mounted!')
})

function Page() {
  useMount(() => analytics.track('page_view'))
  return null
}

const fn = vi.fn()
renderHook(() => useMount(fn)).rerender()
// fn was called once

Warning

The callback runs only on mount. Re-renders do not call it again.

On this page