import {isElement} from "react-is"; export interface iKeepAliveMeta { key: any, type: any, children: any, } /** * 获取有效唯一的ReactNode * @author 韦胜健 * @date 2023.6.3 16:14 */ export function decodeKeepAliveMeta(children: any): null | iKeepAliveMeta { if (children == null || children === false) { return null; } const valueType = typeof children; switch (valueType) { case "string": case "number": case "boolean": return { type: valueType, key: children, children }; } if (isElement(children)) { return { type: children.type, key: children.key, children }; } if (Array.isArray(children)) { console.error(`KeepAlive: can accept only one child, array children is not available!`); return null; } return null; }