Closed ybf970928 closed 1 month ago
需要兼容一下React 16.8
import { startTransition as reactStartTransition } from 'react';
export const safeStartTransition = (callback: () => void) => {
if (typeof reactStartTransition === 'function') {
reactStartTransition(callback);
} else {
// 如果 startTransition 不可用,直接执行回调
callback();
}
};
需要兼容一下React 16.8
import { startTransition as reactStartTransition } from 'react'; export const safeStartTransition = (callback: () => void) => { if (typeof reactStartTransition === 'function') { reactStartTransition(callback); } else { // 如果 startTransition 不可用,直接执行回调 callback(); } };
突然发现, 好像顺带着也把antd的下拉框回显时机错误之类的问题也解决掉了😂, 不在需要在onBeforeActive内处理
very nice!
说明: 当项目当中使用到了类似SWR或者react-query的请求库时, 由于请求库代码内部通过 useLayoutEffect 进行key的验证, 但是优先级低于KeepAlive 里的 setCacheNodes, 所以会出现 A页面切换到B页面后, A页面接口又被错误的调用一次