Skip to content

Commit

Permalink
v3.0.1-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
ibnlanre committed Sep 26, 2023
1 parent 1f2b30b commit e23f806
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
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.0.0-beta",
"version": "3.0.1-beta",
"description": "React state management library",
"main": "cjs/index.js",
"module": "esm/index.js",
Expand Down
10 changes: 6 additions & 4 deletions src/component/useAtom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Atom } from "definition";
import { useState, useEffect } from "react";
import { useState, useEffect, SetStateAction } from "react";
import { isSetStateFunction } from "utilities";

/**
* Custom hook to access and manage an isolated state within an Atom storage.
Expand All @@ -21,9 +22,10 @@ export function useAtom<State, Run, Residue, Data, Context>(
}, []);

const atom = get(state);
const setAtom = (value: State) => {
next(set(value));
const setAtom = (value: State | SetStateAction<State>) => {
const isFunction = isSetStateFunction(value);
next(set(isFunction ? value(store.value) : value));
};

return [atom, setAtom] as const;
}

0 comments on commit e23f806

Please sign in to comment.