Skip to content

Commit 87bc310

Browse files
committed
Upgraded packages and added a unmount fix
1 parent 4fd82ff commit 87bc310

File tree

10 files changed

+3388
-3050
lines changed

10 files changed

+3388
-3050
lines changed

dist/index.js

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.modern.js

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.modern.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/types.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { Dispatch, SetStateAction } from "react";
21
import { Dispatcher } from "./dispatcher";
32
export declare type SessionValueType = {} | null | undefined;
43
export declare type SessionGenericData = {
54
[key: string]: SessionValueType;
65
};
7-
export declare type SessionDispatchFunc = Dispatch<SetStateAction<any>>;
6+
export declare type SessionDispatchFunc = (value: any) => void;
87
export declare type SessionContextKey = string;
98
export declare type SessionOnChange<DataType extends SessionGenericData> = (data: DataType) => void;
109
export declare type SessionGenericContext<DataType extends SessionGenericData = SessionGenericData> = {

example/yarn.lock

Lines changed: 1496 additions & 1352 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@peteck/react-context-session",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Arbitrary session data with support for multiple contexts",
55
"author": "Peteck",
66
"license": "MIT",

src/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { Dispatch, SetStateAction } from "react";
21
import { Dispatcher } from "./dispatcher";
32

43
export type SessionValueType = {} | null | undefined;
54
export type SessionGenericData = { [key: string]: SessionValueType };
6-
export type SessionDispatchFunc = Dispatch<SetStateAction<any>>;
5+
export type SessionDispatchFunc = (value: any) => void;
76
export type SessionContextKey = string;
87
export type SessionOnChange<DataType extends SessionGenericData> = (
98
data: DataType,

src/use-session.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,19 @@ export function useSessionBase<
4747
}
4848

4949
useEffect(() => {
50+
let didUnmount = false;
51+
5052
for (let i = 0; i < k.length; i++) {
51-
context.dispatcher.register(
52-
k[i] as string,
53-
states[k[i] as string][1],
54-
);
53+
context.dispatcher.register(k[i] as string, (value) => {
54+
if (!didUnmount) {
55+
states[k[i] as string][1](value);
56+
}
57+
});
5558
}
5659

5760
return () => {
61+
didUnmount = true;
62+
5863
for (let i = 0; i < k.length; i++) {
5964
context.dispatcher.unregister(
6065
k[i] as string,

yarn.lock

Lines changed: 1852 additions & 1685 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)