react-usekit

Beta

isEmpty

Check if a value is empty (null, undefined, empty string, array, or object).

Installation

npx react-usekit@latest init

Select: utils → TypeScript or JavaScript → path -> isEmpty

Usage

import { isEmpty } from "./utils/isEmpty";

function App() {
  const emptyString = "";
  const emptyArray = [];
  const emptyObject = {};
  const nonEmpty = "hello";

  return (
    <div>
      <p>Empty string: {isEmpty(emptyString) ? "true" : "false"}</p>
      <p>Empty array: {isEmpty(emptyArray) ? "true" : "false"}</p>
      <p>Empty object: {isEmpty(emptyObject) ? "true" : "false"}</p>
      <p>Non-empty string: {isEmpty(nonEmpty) ? "true" : "false"}</p>
    </div>
  );
}

API

Parameters

ParameterTypeDescription
valueanyThe value to check

Returns

TypeDescription
booleanTrue if the value is empty, false otherwise