https://github.com/alloc/react-layout-effect
useLayoutEffect with SSR fallback and React Native support
https://github.com/alloc/react-layout-effect
react-hooks react-native react-ssr reactjs
Last synced: 9 months ago
JSON representation
useLayoutEffect with SSR fallback and React Native support
- Host: GitHub
- URL: https://github.com/alloc/react-layout-effect
- Owner: alloc
- License: mit
- Created: 2019-11-10T15:23:15.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-05T21:53:48.000Z (almost 6 years ago)
- Last Synced: 2025-04-25T00:48:34.788Z (10 months ago)
- Topics: react-hooks, react-native, react-ssr, reactjs
- Language: TypeScript
- Homepage:
- Size: 7.81 KB
- Stars: 12
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-layout-effect
Tiny package dedicated to an isomorphic `useLayoutEffect`.
More info: https://github.com/reduxjs/react-redux/pull/1444
## Usage
```ts
import { useLayoutEffect } from 'react-layout-effect'
const MyComponent = () => {
useLayoutEffect(() => {
console.log('hi')
})
}
```
The "hi" message is only logged when 1+ of these is true:
- `window.document.createElement` exists
- using a bundler that supports ".native.js" overrides
The warning message [thrown by React](https://github.com/facebook/react/issues/14927) is avoided in SSR environments.