Binds argments to functions with memoization of infinite depth.
bind(fnc, arg1[, arg2[, ...]])
The function to be bound
The arguments to bind
A copy of the function with the arguments bound to it and this
set to undefined
. If these argument have been bound to the function before, a cached copy with the same reference is returned.
import bind from 'pure-bind';
class MyComponent extends React.Component {
render() {
return (
<MySubComponent onClick={bind(setValue, 1)} />
)
}
}
No matter how many times MyComponent is rerendered, MySubComponent will always get an onClick prop with the same refernce allowing it to perform a strict equality check in its shouldComponentUpate logic.