1.1.2 • Published 2 years ago

use-page-lifecycle v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

usePageLifecycle

The hook returns the current state of the page's lifecycle and whether the page has been removed from a hidden tab.

According to the Page Lifecycle API, a page can have one of the following states at any given time:

  • Active
  • Passive
  • Hidden
  • Frozen
  • Terminated
  • Discarded

Install

To install package run:

npm install --save use-page-lifecycle

Usage

import { useEffect } from 'react'
import { LifecycleState, usePageLifecycle } from 'use-page-lifecycle'

export default () => {
  const [lifecycleState] = usePageLifecycle()

  useEffect(() => {
      if (lifecycleState === LifecycleState.FROZEN) {
        // some action
      }
  }, [lifecycleState])
    
  return (
    <div>
      <h1>use-page-lifecycle</h1>
    </div>
  )
}

License

MIT

1.1.2

2 years ago

1.1.1

2 years ago

1.0.2

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago