react-is
Brand checking of React Elements.
Last updated a month ago by gaearon .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm 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 element type.

Installation

# Yarn
yarn add react-is

# NPM
npm install react-is

Usage

Determining if a Component is Valid

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

class ClassComponent extends React.Component {
  render() {
    return React.createElement("div");
  }
}

const FunctionComponent = () => React.createElement("div");

const ForwardRefComponent = React.forwardRef((props, ref) =>
  React.createElement(Component, { forwardedRef: ref, ...props })
);

const Context = React.createContext(false);

ReactIs.isValidElementType("div"); // true
ReactIs.isValidElementType(ClassComponent); // true
ReactIs.isValidElementType(FunctionComponent); // true
ReactIs.isValidElementType(ForwardRefComponent); // true
ReactIs.isValidElementType(Context.Provider); // true
ReactIs.isValidElementType(Context.Consumer); // true
ReactIs.isValidElementType(React.createFactory("div")); // true

Determining an Element's Type

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

  • 0.0.0-experimental-4ead6b530                                ...           experimental (2 months ago)
  • 17.0.1                                ...           latest (a month ago)
  • 0.0.0-8e5adfbd7                                ...           next (a month ago)

154 Versions

  • 17.0.1                                ...           a month ago
  • 0.0.0-8e5adfbd7                                ...           a month ago
  • 17.0.0                                ...           a month ago
  • 0.0.0-experimental-4ead6b530                                ...           2 months ago
  • 17.0.0-rc.3                                ...           2 months ago
  • 0.0.0-4ead6b530                                ...           2 months ago
  • 17.0.0-rc.2                                ...           2 months ago
  • 0.0.0-3834174dd                                ...           2 months ago
  • 17.0.0-rc.1                                ...           3 months ago
  • 0.0.0-4e6999103                                ...           3 months ago
  • 17.0.0-rc.0                                ...           4 months ago
  • 0.0.0-experimental-94c0244ba                                ...           4 months ago
  • 0.0.0-94c0244ba                                ...           4 months ago
  • 0.0.0-experimental-f77c7b9d7                                ...           4 months ago
  • 0.0.0-f77c7b9d7                                ...           4 months ago
  • 0.0.0-experimental-3d0895557                                ...           4 months ago
  • 0.0.0-3d0895557                                ...           4 months ago
  • 0.0.0-experimental-ede917064                                ...           4 months ago
  • 0.0.0-experimental-4c8c98ab9                                ...           4 months ago
  • 0.0.0-experimental-7f28234f8                                ...           5 months ago
  • 0.0.0-7f28234f8                                ...           5 months ago
  • 0.0.0-experimental-33c3af284                                ...           7 months ago
  • 0.0.0-33c3af284                                ...           7 months ago
  • 0.0.0-experimental-e5d06e34b                                ...           8 months ago
  • 0.0.0-experimental-d7382b6c4                                ...           8 months ago
  • 0.0.0-d7382b6c4                                ...           8 months ago
  • 16.13.1                                ...           8 months ago
  • 0.0.0-da834083c                                ...           8 months ago
  • 0.0.0-experimental-aae83a4b9                                ...           8 months ago
  • 0.0.0-experimental-8b155d261                                ...           9 months ago
  • 0.0.0-235a6c4af                                ...           9 months ago
  • 0.0.0-experimental-235a6c4af                                ...           9 months ago
  • 0.0.0-experimental-355970aa4                                ...           9 months ago
  • 16.13.0                                ...           9 months ago
  • 0.0.0-experimental-d28bd2994                                ...           9 months ago
  • 0.0.0-d28bd2994                                ...           9 months ago
  • 0.0.0-experimental-8d7535e54                                ...           9 months ago
  • 0.0.0-8d7535e54                                ...           9 months ago
  • 0.0.0-5de5b6150                                ...           9 months ago
  • 0.0.0-experimental-5de5b6150                                ...           9 months ago
  • 0.0.0-ea6ed3dbb                                ...           9 months ago
  • 0.0.0-experimental-ea6ed3dbb                                ...           9 months ago
  • 0.0.0-experimental-241c4467e                                ...           10 months ago
  • 0.0.0-241c4467e                                ...           10 months ago
  • 0.0.0-experimental-57333ca33                                ...           10 months ago
  • 0.0.0-57333ca33                                ...           10 months ago
  • 0.0.0-experimental-f42431abe                                ...           a year ago
  • 0.0.0-f42431abe                                ...           a year ago
  • 0.0.0-experimental-2c169a568                                ...           a year ago
  • 0.0.0-experimental-3f3fe0874                                ...           a year ago
  • 0.0.0-experimental-0e6839614                                ...           a year ago
  • 16.12.0                                ...           a year ago
  • 0.0.0-experimental-b53ea6ca0                                ...           a year ago
  • 0.0.0-b53ea6ca0                                ...           a year ago
  • 0.0.0-38dd17ab9                                ...           a year ago
  • 0.0.0-experimental-38dd17ab9                                ...           a year ago
  • 0.0.0-f6b8d31a7                                ...           a year ago
  • 0.0.0-experimental-f6b8d31a7                                ...           a year ago
  • 16.11.0                                ...           a year ago
  • 0.0.0-experimental-5faf377df                                ...           a year ago
  • 0.0.0-5faf377df                                ...           a year ago
  • 0.0.0-experimental-1022ee0ec                                ...           a year ago
  • 0.0.0-1022ee0ec                                ...           a year ago
  • 0.0.0-experimental-7082d5a2d                                ...           a year ago
  • 0.0.0-7082d5a2d                                ...           a year ago
  • 0.0.0-experimental-d7feeb25a                                ...           a year ago
  • 0.0.0-experimental-d364d8555                                ...           a year ago
  • 16.10.2                                ...           a year ago
  • 0.0.0-4ab6305f6                                ...           a year ago
  • 16.10.1                                ...           a year ago
  • 0.0.0-d346d9208                                ...           a year ago
  • 16.10.0                                ...           a year ago
  • 0.0.0-3694a3b5e                                ...           a year ago
  • 0.0.0-b4b8a349a                                ...           a year ago
  • 0.0.0-45b6443c9                                ...           a year ago
  • 0.0.0-8d5403877                                ...           a year ago
  • 16.9.0                                ...           a year ago
  • 16.9.0-rc.0                                ...           a year ago
  • 0.0.0-a1dbb852c                                ...           a year ago
  • 0.0.0-375616788                                ...           a year ago
  • 0.0.0-db3ae32b8                                ...           a year ago
  • 0.0.0-bbd21066e                                ...           a year ago
  • 0.0.0-b4178af81                                ...           a year ago
  • 0.0.0-424099da6                                ...           a year ago
  • 0.0.0-9f395904c                                ...           a year ago
  • 0.0.0-fa1e8df11                                ...           a year ago
  • 0.0.0-50b50c26f                                ...           2 years ago
  • 0.0.0-6da04b5d8                                ...           2 years ago
  • 0.0.0-fb28e9048                                ...           2 years ago
  • 0.0.0-4221565e1                                ...           2 years ago
  • 0.0.0-9ebe1768a                                ...           2 years ago
  • 0.0.0-a9eff329c                                ...           2 years ago
  • 16.9.0-alpha.0                                ...           2 years ago
  • 0.0.0-c35e37aab                                ...           2 years ago
  • 16.8.6                                ...           2 years ago
  • 0.0.0-297165f1e                                ...           2 years ago
  • 16.8.5                                ...           2 years ago
  • 0.0.0-f9e41e3a5                                ...           2 years ago
  • 0.0.0-679402a66                                ...           2 years ago
  • 16.8.4                                ...           2 years ago
  • 0.0.0-741aa17a3                                ...           2 years ago
  • 16.8.3                                ...           2 years ago
  • 0.0.0-29b7b775f                                ...           2 years ago
  • 0.0.0-b668168d4                                ...           2 years ago
  • 16.8.2                                ...           2 years ago
  • 0.0.0-dfabb77a9                                ...           2 years ago
  • 0.0.0-0e4135e8c                                ...           2 years ago
  • 16.8.1                                ...           2 years ago
  • 0.0.0-11565a207                                ...           2 years ago
  • 16.8.0                                ...           2 years ago
  • 0.0.0-d1326f466                                ...           2 years ago
  • 0.0.0-267ed9814                                ...           2 years ago
  • 0.0.0-fec00a869                                ...           2 years ago
  • 16.8.0-alpha.1                                ...           2 years ago
  • 0.0.0-3e15b1c69                                ...           2 years ago
  • 16.8.0-alpha.0                                ...           2 years ago
  • 0.0.0-f22621f88                                ...           2 years ago
  • 16.7.0                                ...           2 years ago
  • 0.0.0-4a1072194                                ...           2 years ago
  • 0.0.0-7325ebe4d                                ...           2 years ago
  • 0.0.0-c5b7d26c7                                ...           2 years ago
  • 0.0.0-88ada9819                                ...           2 years ago
  • 0.0.0-ed4c4a51c                                ...           2 years ago
  • 16.7.0-alpha.2                                ...           2 years ago
  • 16.7.0-alpha.1                                ...           2 years ago
  • 16.6.3                                ...           2 years ago
  • 0.0.0-0c756fb-f7f79fd                                ...           2 years ago
  • 16.6.2                                ...           2 years ago
  • 0.0.0-0c756fb-697f004                                ...           2 years ago
  • 0.0.0-8b3c1e4-1d1a717                                ...           2 years ago
  • 0.0.0-a8988e4-1d1a717                                ...           2 years ago
  • 0.0.0-d5e1bf0-aee1b84                                ...           2 years ago
  • 16.6.1                                ...           2 years ago
  • 16.7.0-alpha.0                                ...           2 years ago
  • 16.6.0                                ...           2 years ago
  • 16.6.0-alpha.8af6728                                ...           2 years ago
  • 16.6.0-alpha.400d197                                ...           2 years ago
  • 16.5.2                                ...           2 years ago
  • 16.6.0-alpha.0                                ...           2 years ago
  • 16.5.1                                ...           2 years ago
  • 16.5.0                                ...           2 years ago
  • 16.4.2                                ...           2 years ago
  • 16.4.1                                ...           2 years ago
  • 16.4.0                                ...           3 years ago
  • 16.3.2                                ...           3 years ago
  • 16.3.1                                ...           3 years ago
  • 16.3.0                                ...           3 years ago
  • 16.3.0-rc.0                                ...           3 years ago
  • 16.3.0-alpha.3                                ...           3 years ago
  • 16.3.0-alpha.2                                ...           3 years ago
  • 16.4.0-alpha.0911da3                                ...           3 years ago
  • 16.4.0-alpha.3174632                                ...           3 years ago
  • 16.3.0-alpha.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Downloads
Today 407
This Week 25,095
This Month 407
Last Day 24,688
Last Week 145,239
Last Month 611,186
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (792)

Copyright 2014 - 2016 © taobao.org |