Skip to content

Commit b2077ca

Browse files
committed
react 19.2 useEffect replaced by useSyncExternalStore
1 parent d4d5e8b commit b2077ca

File tree

9 files changed

+445
-388
lines changed

9 files changed

+445
-388
lines changed

dist.es2015/router.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { PathMatch } from './context';
44
export interface RouterProps extends React.PropsWithChildren {
55
navigate?: (path: string, data?: any, replace?: boolean) => void;
66
match?: (path: string) => PathMatch;
7-
changeEvent?: string;
7+
changeEvent?: string | null;
88
getCurrentPath?: () => string;
99
}
1010
export default function Router(props: RouterProps): React.ReactElement<React.ProviderProps<RouterContext>, string | React.JSXElementConstructor<any>> | null;

dist.es2015/router.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,20 @@ function defNavigate(path, data, replace) {
3939
window.history.pushState(data, '', path);
4040
}
4141
}
42+
function getUndefinedSnapshot() {
43+
}
4244
export default function Router(props) {
4345
var children = props.children, _a = props.navigate, n = _a === void 0 ? defNavigate : _a, _b = props.match, m = _b === void 0 ? defMatch : _b, _c = props.changeEvent, c = _c === void 0 ? defChangeEvent : _c, _d = props.getCurrentPath, g = _d === void 0 ? defGetCurrentPath : _d;
4446
var _e = React.useState(g()), path = _e[0], setPath = _e[1];
45-
React.useEffect(function () {
47+
var subscribeEvent = React.useCallback(function () {
4648
if (!c) {
47-
return;
49+
return getUndefinedSnapshot;
4850
}
4951
var eventHandler = function () { return setPath(g()); };
5052
window.addEventListener(c, eventHandler);
5153
return function () { return window.removeEventListener(c, eventHandler); };
52-
}, [c, g, setPath]);
54+
}, [c, g]);
55+
React.useSyncExternalStore(subscribeEvent, getUndefinedSnapshot);
5356
if (!children) {
5457
return null;
5558
}

dist/router.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { PathMatch } from './context';
44
export interface RouterProps extends React.PropsWithChildren {
55
navigate?: (path: string, data?: any, replace?: boolean) => void;
66
match?: (path: string) => PathMatch;
7-
changeEvent?: string;
7+
changeEvent?: string | null;
88
getCurrentPath?: () => string;
99
}
1010
export default function Router(props: RouterProps): React.ReactElement<React.ProviderProps<RouterContext>, string | React.JSXElementConstructor<any>> | null;

dist/router.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,20 @@ function defNavigate(path, data, replace) {
4242
window.history.pushState(data, '', path);
4343
}
4444
}
45+
function getUndefinedSnapshot() {
46+
}
4547
function Router(props) {
4648
var children = props.children, _a = props.navigate, n = _a === void 0 ? defNavigate : _a, _b = props.match, m = _b === void 0 ? defMatch : _b, _c = props.changeEvent, c = _c === void 0 ? defChangeEvent : _c, _d = props.getCurrentPath, g = _d === void 0 ? defGetCurrentPath : _d;
4749
var _e = React.useState(g()), path = _e[0], setPath = _e[1];
48-
React.useEffect(function () {
50+
var subscribeEvent = React.useCallback(function () {
4951
if (!c) {
50-
return;
52+
return getUndefinedSnapshot;
5153
}
5254
var eventHandler = function () { return setPath(g()); };
5355
window.addEventListener(c, eventHandler);
5456
return function () { return window.removeEventListener(c, eventHandler); };
55-
}, [c, g, setPath]);
57+
}, [c, g]);
58+
React.useSyncExternalStore(subscribeEvent, getUndefinedSnapshot);
5659
if (!children) {
5760
return null;
5861
}

0 commit comments

Comments
 (0)