Socket
Book a DemoInstallSign in
Socket

no-bind

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

no-bind

No more `bind` in JSX

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

noBind

No more bind in JSX.

Motivation

The reason why I started building this little utility was lead by one of the rules applied in the React eslint config of Airbnb. There they point out that when using .bind inside of your render method will make the amount of memory used by your app bigger with each "rerender". This is because .bind return a copy of the that bound function. This utility gives you the same behavior as .bind would without making a copy of your function. As so be more memory efficient.

Usage

import noBind from 'no-bind';

function clickHandler(id, e) {
  console.log(id, e);
}

function MyList(props) {
  const { listItems } = props;
  return listItems.map(item => (
    <button onClick={noBind(clickHandler, item.id)}>
      Click Me
    </button>
  ))
}

Keywords

bind

FAQs

Package last updated on 09 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts