Skip to content

Commit

Permalink
Improve hook style
Browse files Browse the repository at this point in the history
  • Loading branch information
kormanowsky committed Oct 17, 2020
1 parent 8660207 commit 36b1b77
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ The new `useBitList()` hook may be used in React applications.
```javascript
import BitList from "js-bit-list";
const MyBitList = BitList.useKeys(["myKey"]);
const [getList, withList] = useBitList(MyBitList, {myKey: 1});
const [getList, setList] = useBitList(MyBitList, {myKey: 1});
// Later
const listNumber = getList().toNumber();
withList(list => {
list.setObject({myKey: 0})
});
const listNumber = getList().toNumber(),
list = getList();
list.setObject({myKey: 0});
setList(list);
```
### See example.js for working example
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,19 @@ if (typeof window === "object") {
window.BitList = BitList;
}

// ReactJS support
// ReactJS support

/**
* A React hook for bit list.
* @param {*} bitListClass A bit list class (child of BitList) to use
* @param {*} initialValue An initial value to use.
* A React hook for bit list.
* @param {*} bitListClass A bit list class (child of BitList) to use
* @param {*} initialValue An initial value to use.
* @since 1.3.0
* @example const [getBitList, withBitList] = useBitList(MyBitList, {"mykey":true})
* @example const [getBitList, setBitList] = useBitList(MyBitList, {"mykey":true})
*/
function useBitList(bitListClass, initialValue){
function useBitList(bitListClass, initialValue) {
let instance = new bitListClass(initialValue);
return [() => instance, callback => {callback(instance)}];
return [() => instance, (newInstance) => (instance = newInstance)];
}

export {useBitList};
export { useBitList };
export default BitList;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-bit-list",
"version": "1.3.0",
"version": "1.4.0",
"description": "Store arrays of boolean values in numbers.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 36b1b77

Please sign in to comment.