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
;; Component { return React; } const StatelessComponent = React; const ForwardRefComponent = React; const Context = React; ReactIs; // trueReactIs; // trueReactIs; // trueReactIs; // trueReactIs; // trueReactIs; // trueReactIs; // true
Determining an Element's Type
ConcurrentMode
;; ReactIs; // trueReactIs === ReactIsConcurrentMode; // true
Context
;; const ThemeContext = React; ReactIs; // trueReactIs; // trueReactIs === ReactIsContextProvider; // trueReactIs === ReactIsContextConsumer; // true
Element
;; ReactIs; // trueReactIs === ReactIsElement; // true
Fragment
;; ReactIs; // trueReactIs === ReactIsFragment; // true
Portal
;;; const div = document;const portal = ReactDOM; ReactIs; // trueReactIs === ReactIsPortal; // true
StrictMode
;; ReactIs; // trueReactIs === ReactIsStrictMode; // true