1.1.1 • Published 4 years ago

named-effect v1.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

named-effect

Wrapper around React's useEffect, in-order to require a name for each effect used

Install

npm install named-effect --save

Usage

import useNamedEffect from 'named-effect'
...
const onLayoutThree = useNamedEffect([stateVariable], () => stateVariable === 3).bind(useEffect)

onVariableIsThree(() => {
  console.log(`variable is ${stateVariable}`); // variable is 3
})

Example

import React, { Component } from 'react'

import useNamedEffect from 'named-effect'

function Example() {

  const [currentLayout, setLayout] = useState(0);

  const onLayoutThree = useNamedEffect([currentLayout], () => currentLayout === 3).bind(useEffect);

  onLayoutThree(() => {
    console.log(`layout number ${currentLayout}`); // layout number 3
  })

  const onLayoutChangeClicked = () => {
    setLayout(prev => prev+1);
  }

  return (
    <div className="example">
      <div onClick={onLayoutChangeClicked}>Change layout</div>
    </div>
  );
}

License

MIT © shim2k

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago