diff --git a/README.md b/README.md index e6de675..1f980f6 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file diff --git a/index.js b/index.js index 47c608b..5ab9e78 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/package.json b/package.json index a609926..0f46cda 100644 --- a/package.json +++ b/package.json @@ -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": {