-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Authoritative brand checking library
Can be used without any dependency on React. Plausible replacement for React.isValidElement.
- Loading branch information
1 parent
b52a562
commit 5bd4d81
Showing
3 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# `react-dom` | ||
|
||
This package serves as the entry point of the DOM-related rendering paths. It is intended to be paired with the isomorphic React, which will be shipped as `react` to npm. | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install react react-dom | ||
``` | ||
|
||
## Usage | ||
|
||
### In the browser | ||
|
||
```js | ||
var React = require('react'); | ||
var ReactDOM = require('react-dom'); | ||
|
||
class MyComponent extends React.Component { | ||
render() { | ||
return <div>Hello World</div>; | ||
} | ||
} | ||
|
||
ReactDOM.render(<MyComponent />, node); | ||
``` | ||
|
||
### On the server | ||
|
||
```js | ||
var React = require('react'); | ||
var ReactDOMServer = require('react-dom/server'); | ||
|
||
class MyComponent extends React.Component { | ||
render() { | ||
return <div>Hello World</div>; | ||
} | ||
} | ||
|
||
ReactDOMServer.renderToString(<MyComponent />); | ||
``` | ||
|
||
## API | ||
|
||
### `react-dom` | ||
|
||
- `findDOMNode` | ||
- `render` | ||
- `unmountComponentAtNode` | ||
|
||
### `react-dom/server` | ||
|
||
- `renderToString` | ||
- `renderToStaticMarkup` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var REACT_ELEMENT_TYPE; | ||
var REACT_COROUTINE_TYPE; | ||
var REACT_YIELD_TYPE; | ||
var REACT_PORTAL_TYPE; | ||
var REACT_FRAGMENT_TYPE; | ||
if (typeof Symbol === 'function' && Symbol.for) { | ||
REACT_ELEMENT_TYPE = Symbol.for('react.element'); | ||
REACT_COROUTINE_TYPE = Symbol.for('react.coroutine'); | ||
REACT_YIELD_TYPE = Symbol.for('react.yield'); | ||
REACT_PORTAL_TYPE = Symbol.for('react.portal'); | ||
REACT_FRAGMENT_TYPE = Symbol.for('react.fragment'); | ||
} else { | ||
REACT_ELEMENT_TYPE = 0xeac7; | ||
REACT_COROUTINE_TYPE = 0xeac8; | ||
REACT_YIELD_TYPE = 0xeac9; | ||
REACT_PORTAL_TYPE = 0xeaca; | ||
REACT_FRAGMENT_TYPE = 0xeacb; | ||
} | ||
|
||
function is(object, type) { | ||
return ( | ||
typeof object === 'object' && object !== null && object.$$typeof === type | ||
); | ||
} | ||
|
||
module.exports = { | ||
typeOf(object) { | ||
switch (typeof object === 'object' && object !== null && object.$$typeof) { | ||
case REACT_ELEMENT_TYPE: | ||
return 'ReactElement'; | ||
case REACT_COROUTINE_TYPE: | ||
return 'ReactCoroutine'; | ||
case REACT_YIELD_TYPE: | ||
return 'ReactYield'; | ||
case REACT_PORTAL_TYPE: | ||
return 'ReactPortal'; | ||
case REACT_FRAGMENT_TYPE: | ||
return 'ReactFragment'; | ||
default: | ||
return undefined; | ||
} | ||
}, | ||
isElement(object) { | ||
return is(object, REACT_ELEMENT_TYPE); | ||
}, | ||
isCoroutine(object) { | ||
return is(object, REACT_COROUTINE_TYPE); | ||
}, | ||
isYield(object) { | ||
return is(object, REACT_YIELD_TYPE); | ||
}, | ||
isPortal(object) { | ||
return is(object, REACT_PORTAL_TYPE); | ||
}, | ||
isFragment(object) { | ||
return is(object, REACT_FRAGMENT_TYPE); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "react-is", | ||
"description": "Brand checking of React Elements.", | ||
"keywords": [ | ||
"react" | ||
], | ||
"version": "1.0.0", | ||
"homepage": "https://reactjs.org/", | ||
"bugs": "https://github.com/facebook/react/issues", | ||
"license": "MIT", | ||
"files": [ | ||
"index.js" | ||
], | ||
"main": "index.js", | ||
"repository": "facebook/react", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
} | ||
} |