es-toolkit/docs/reference/function/noop.md
2024-06-08 15:47:44 +09:00

489 B

noop

A no-operation function that does nothing. This can be used as a placeholder or default function.

Signature

function noop(): void;

Returns

(void): This function does not return anything.

Examples

import { noop } from 'es-toolkit/function';

interface Props {
  onChange?: () => void;
}

function MyComponent({ onChange = noop }: Props) {
  // Here onChange is guaranteed to be a function, so it's safe to call.
  onChange();
}