Skip to content

Commit

Permalink
v3.18.2-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
ibnlanre committed Nov 12, 2023
1 parent de2eeae commit afce5c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ This library exports the following APIs to enhance state management and facilita
</td>
<td colspan="4">A <strong>hook</strong> to persist state in Session Storage.</td>
</tr>
<tr>
<td></td>
<td colspan="2">
<code>.cookie</code>
</td>
<td colspan="4">A <strong>hook</strong> to persist state in `document.cookie`.</td>
</tr>
<tr>
<td colspan="2">
<code>createBuilder</code>
Expand Down Expand Up @@ -108,13 +115,15 @@ This library exports the following APIs to enhance state management and facilita

```js
// To persist the state in `localStorage`:
const [state, setState] = usePortal.local("foo");
const [state, setState] = usePortal.local("foo.bar");

// To persist the state in `sessionStorage`:
const [state, setState] = usePortal.session("foo");
const [state, setState] = usePortal.session("foo.bar.baz");

// Accessing the identifier later, doesn't require the use of [.local]
const [counter, setCounter] = usePortal("foo");
// To persist the state in `document.cookie`
const [state, setState] = usePortal.cookie("foo.rim", {
path: "/"
});
```

4. **To manage state outside of a React Component, create an `atom`.**
Expand Down Expand Up @@ -196,8 +205,8 @@ This library exports the following APIs to enhance state management and facilita
// `get` retrieves the keys without invoking the function.
builder.foo.baz.get(); // ["foo", "baz"]

// `get` does not exist if the value is not a function.
builder.foo.use(); // ["foo"]
// `get` also allows you to add more keys
builder.foo.baz.get("test"); // ["foo", "baz", "test"]
```
- Get nested `values`:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ibnlanre/portal",
"version": "3.18.1-beta",
"version": "3.18.2-beta",
"description": "React state management library",
"main": "cjs/index.js",
"module": "esm/index.js",
Expand Down
12 changes: 0 additions & 12 deletions src/component/makeUsePortal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,6 @@ export function makeUsePortal<Ledger extends Record<string, any>>(
});
};

/**
* Custom hook to access and manage state in the portal system with cookie support.
*
* @template Path The type of the path.
* @template State The type of the state.
* @template Store The type of the store.
*
* @param {Path} path The path to the store value.
* @param {CookieOptions} cookieOptions The options for the cookie.
*
* @returns {PortalState<State>} A tuple containing the current state and a function to update the state.
*/
usePortal.cookie = function useCookie<
Path extends Paths<Ledger>,
State extends GetValueByPath<Ledger, Path>
Expand Down

0 comments on commit afce5c5

Please sign in to comment.