Skip to content

Commit

Permalink
Updated react-is README to show new isValidElementType()
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn committed Mar 29, 2018
1 parent 96fe3b1 commit 53fdc19
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions packages/react-is/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `react-is`

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

## Installation

Expand All @@ -14,7 +14,37 @@ npm install react-is --save

## Usage

### AsyncMode
### Determining if a Component is Valid

```js
import * as ReactIs from "react-is";

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

const StatelessComponent = () => 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(StatelessComponent); // 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

#### AsyncMode

```js
import React from "react";
Expand All @@ -24,7 +54,7 @@ ReactIs.isAsyncMode(<React.unstable_AsyncMode />); // true
ReactIs.typeOf(<React.unstable_AsyncMode />) === ReactIs.AsyncMode; // true
```

### Context
#### Context

```js
import React from "react";
Expand All @@ -38,7 +68,7 @@ ReactIs.typeOf(<ThemeContext.Provider />) === ReactIs.ContextProvider; // true
ReactIs.typeOf(<ThemeContext.Consumer />) === ReactIs.ContextConsumer; // true
```

### Element
#### Element

```js
import React from "react";
Expand All @@ -48,7 +78,7 @@ ReactIs.isElement(<div />); // true
ReactIs.typeOf(<div />) === ReactIs.Element; // true
```

### Fragment
#### Fragment

```js
import React from "react";
Expand All @@ -58,7 +88,7 @@ ReactIs.isFragment(<></>); // true
ReactIs.typeOf(<></>) === ReactIs.Fragment; // true
```

### Portal
#### Portal

```js
import React from "react";
Expand All @@ -72,7 +102,7 @@ ReactIs.isPortal(portal); // true
ReactIs.typeOf(portal) === ReactIs.Portal; // true
```

### StrictMode
#### StrictMode

```js
import React from "react";
Expand Down

0 comments on commit 53fdc19

Please sign in to comment.