Skip to content

Commit

Permalink
v0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
roolanrewaju committed Jun 11, 2023
1 parent 1364186 commit 67879e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ibnlanre/portal",
"version": "0.0.6",
"version": "0.0.7",
"description": "React state management library based on RxJS Behavior Subject",
"main": "dist/index",
"files": [
Expand Down Expand Up @@ -39,7 +39,19 @@
"build": "tsup",
"package": "yarn build & yarn publish --access public"
},
"author": "Ridwan Olanrewaju",
"keywords": [
"state",
"context"
],
"repository": {
"type": "git",
"url": "git+https://github.com/ibnlanre/portal.git"
},
"author": "Ridwan Olanrewaju <olaitanlanre28@gmail.com>",
"bugs": {
"url": "https://github.com/ibnlanre/portal/issues"
},
"homepage": "https://github.com/ibnlanre/portal#readme",
"license": "MIT",
"devDependencies": {
"@swc/core": "^1.3.61",
Expand Down
10 changes: 5 additions & 5 deletions src/components/usePortal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ export function usePortal<S, A>(
const observable = entries.get(key) ?? subject;
const dispatch = reducers.get(key) ?? reducer;

const [state, setState] = useState(initialState as S);
const subRef = useRef<Subscription>();

const [state, setState] = useState(observable.getValue());

useEffect(() => {
if (!entries.has(key)) setEntries(key, observable);
if (!entries.has(key)) setEntries(key, subject);
if (reducer && !reducers.has(key)) setReducers(key, reducer);
}, []);


const subRef = useRef<Subscription>();
useEffect(() => {
subRef.current = observable.subscribe(setState);

Expand Down

0 comments on commit 67879e9

Please sign in to comment.