Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jedwatson/exenv
React's ExecutionEnvironment module extracted for use in other packages & components
https://github.com/jedwatson/exenv
Last synced: 17 days ago
JSON representation
React's ExecutionEnvironment module extracted for use in other packages & components
- Host: GitHub
- URL: https://github.com/jedwatson/exenv
- Owner: JedWatson
- License: other
- Created: 2015-04-14T01:34:06.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-11-12T02:25:46.000Z (about 6 years ago)
- Last Synced: 2024-10-23T00:04:19.636Z (23 days ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 233
- Watchers: 6
- Forks: 15
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# exenv
React's ExecutionEnvironment module extracted for use in other packages & components.
## Usage
```
npm install exenv --save
``````js
var ExecutionEnvironment = require('exenv');// You now have...
ExecutionEnvironment.canUseDOM // is the DOM available? i.e window document etc.
ExecutionEnvironment.canUseWorkers // are Web Workers available?
ExecutionEnvironment.canUseEventListeners // are Events available? i.e addEventListener etc.
ExecutionEnvironment.canUseViewport // is there a viewport? i.e window.screen
```### Differences from React's ExecutionEnvironment
The `ExecutionEnvironment` lib in React 0.13 includes an `isInWorker` property, which is `!canUseDOM`. This is highly specific to React internals and probably (a) hacky and (b) not useful to other packages, so it has been left out. Please open an issue with your thoughts if you disagree or have a better idea.
## Why?
A number of packages and components use React's private ExecutionEnvironment lib to detect available features, particularly to detect server-side rendering, e.g
```
canUseDOM = require('react/lib/ExecutionEnvironment').canUseDOM; // BAD
```**It is bad practice to use React internals** and this is likely to be broken / disabled in the future.
Use this package instead!