Documentation
Logging warnings with traceability in React

useWarning

The useWarning hook provides a way to log warnings to the console in a consistent and controlled manner. This hook is particularly useful for development purposes, allowing you to flag potential issues in your code with clear messages that can optionally be associated with a specific component.

Usage

First, you need to import the useWarning hook from the kitchn package.

import { useWarning } from "kitchn";

Example

Here is an example of how to use the useWarning hook in a component:

Check the console for a warning message.

Code Editor
() => {
  useWarning("This is a warning message", "ExampleComponent");

  return (
    <Text>Check the console for a warning message.</Text>
  );
};

Parameters

The useWarning hook accepts the following parameters:

NameTypeDescription
isBrowserbooleantrue if the code is running in the browser; false otherwise.
isServer booleantrue if the code is running on the server; false otherwise.

Return Value

The useWarning hook does not return any value.

Last updated on