Skip to content

Add SSR wrapper for useLayoutEffect #59

@joduplessis

Description

@joduplessis

https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a

import useLayoutEffect from './use-isomorphic-layout-effect';
function App() {
  useLayoutEffect(() => {
    console.log('hello there');
  }, []);
  return 'Hello world';
};
// use-isomorphic-layout-effect.js
import { useLayoutEffect, useEffect } from 'react';
const useIsomorphicLayoutEffect =
  typeof window !== 'undefined' ? useLayoutEffect : useEffect;
export default useIsomorphicLayoutEffect;

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs more infoImprovements or additions to documentation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions