react-is
Brand checking of React Elements.
Last updated 9 years ago by acdlite .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install react-is 
SYNC missed versions from official npm registry.

react-is

This package allows you to test arbitrary values and see if they're a particular React type, e.g. React Elements.

Installation

# Yarn
yarn add react-is

# NPM
npm install react-is --save

Usage

AsyncMode

import React from "react";
import * as ReactIs from 'react-is';

ReactIs.isAsyncMode(<React.unstable_AsyncMode />); // true
ReactIs.typeOf(<React.unstable_AsyncMode />) === ReactIs.AsyncMode; // true

Context

import React from "react";
import * as ReactIs from 'react-is';

const ThemeContext = React.createContext("blue");

ReactIs.isContextConsumer(<ThemeContext.Consumer />); // true
ReactIs.isContextProvider(<ThemeContext.Provider />); // true
ReactIs.typeOf(<ThemeContext.Provider />) === ReactIs.ContextProvider; // true
ReactIs.typeOf(<ThemeContext.Consumer />) === ReactIs.ContextConsumer; // true

Element

import React from "react";
import * as ReactIs from 'react-is';

ReactIs.isElement(<div />); // true
ReactIs.typeOf(<div />) === ReactIs.Element; // true

Fragment

import React from "react";
import * as ReactIs from 'react-is';

ReactIs.isFragment(<></>); // true
ReactIs.typeOf(<></>) === ReactIs.Fragment; // true

Portal

import React from "react";
import ReactDOM from "react-dom";
import * as ReactIs from 'react-is';

const div = document.createElement("div");
const portal = ReactDOM.createPortal(<div />, div);

ReactIs.isPortal(portal); // true
ReactIs.typeOf(portal) === ReactIs.Portal; // true

StrictMode

import React from "react";
import * as ReactIs from 'react-is';

ReactIs.isStrictMode(<React.StrictMode />); // true
ReactIs.typeOf(<React.StrictMode />) === ReactIs.StrictMode; // true

Current Tags

  • 19.1.10                                ...           backport (a month ago)
  • 19.0.0-beta-26f2496093-20240514                                ...           beta (3 years ago)
  • 19.3.0-canary-edae846a-20261125                                ...           canary (2 days ago)
  • 0.0.0-experimental-edae846a-20261125                                ...           experimental (2 days ago)
  • 19.3.1                                ...           latest (a month ago)
  • 19.3.0-canary-d5736f09-20260507                                ...           next (7 months ago)
  • 19.0.0-rc.1                                ...           rc (2 years ago)

2883 Versions


© 2010 - cnpmjs.org x YWFE | Home | YWFE