use-callback-creator
v1.1.6
Published
A hook to add a lot of similar callbacks inside a React component
Downloads
45
Readme
use-callback-creator
A hook to add a lot of similar callbacks inside a React component
Install
npm install --save use-callback-creator
Usage
import React, { useState } from 'react'
import useCallbackCreator from 'use-callback-creator'
const Example = () => {
const [counters, setCounter]=useState([0,0,0,0]);
const handleAdd = useCallbackCreator((index)=>{
const newCounters=[...counters];
newCounters[index]+=1;
setCounters(counters);
},[counters]);
return (
<div>
{counters.map( (count, index)=>
<div>{count} <button onClick={handleAdd(index)}>Add</button>
)}
</div>
)
}
License
MIT © MarkEhr
This hook is created using create-react-hook.