react-layout-effect

1.0.5 • Public • Published

react-layout-effect

Tiny package dedicated to an isomorphic useLayoutEffect.

More info: https://github.com/reduxjs/react-redux/pull/1444

Usage

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 is avoided in SSR environments.

Readme

Keywords

none

Package Sidebar

Install

npm i react-layout-effect

Weekly Downloads

42,696

Version

1.0.5

License

MIT

Unpacked Size

3.19 kB

Total Files

11

Last publish

Collaborators

  • aleclarson