react-mutable-refs

4.1.0 • Public • Published

react-mutable-refs

react-mutable-refs provides utility to create mutable ref or function. This helps you in avoiding unwanted React re-renders.

Install

yarn add react-mutable-refs

or

npm i react-mutable-refs

Usage

import { useMutableFunc, useMutableRef } from 'react-mutable-refs'

function ExamplePage(props) {
  const { item } = props
  const mutableItemRef = useMutableRef(item)

  // myFunciton will not re-render due to any change item
  const myFunction = React.useCallback(() => {
    if (mutableItemRef.current) {
      // do something
    }
  }, [mutableItemRef])


}


function useExampleHook(props) {
  const { prop1, prop2 } = props

  const someFunction = React.useCallback(() => {
    if (prop1 && prop2) {
      // do something
    }
  }, [prop1, prop2])

  
  const mutableFunc = useMutableFunc(someFunction)
  // mutableFunc is not affected by prop1, prop2 etc. and avoid unwanted re-render of React.
  return mutableFunc
}

Components/Hooks/Functions

  • useMutableRef
  • useMutableFunc
  • mergeRefs
  • assignRefs
  • trackDefaultRef
  • trackLastRef
  • Refreshable
  • makeRefreshable

Author

Prolincur Technologies

Package Sidebar

Install

npm i react-mutable-refs

Weekly Downloads

21

Version

4.1.0

License

Apache-2.0

Unpacked Size

40.5 kB

Total Files

4

Last publish

Collaborators

  • prolincur