UNPKG

rsc-superjson

Version:

A superjson wrapper for React Server Components (RSC) and Next.js

26 lines 1.4 kB
import { jsx as _jsx } from "react/jsx-runtime"; import SuperJSONComponent from "./superjson-component"; import { serialize } from "./superjson-deserialize"; /** * Wraps a component with SuperJSON serialization. * Note that next.js [parallel route slots](https://nextjs.org/docs/app/building-your-application/routing/parallel-routes#slots) are not supported and must be excluded via `excludedSuperjsonProps`. * The implicit `children` slot is excluded by default. * @param Component */ export function withSuperjson(Component) { return function WrappedComponent(props) { var _a, _b; const propsWithoutExcludedProps = Object.assign({}, props); delete propsWithoutExcludedProps.children; for (const prop of (_a = props.excludedSuperjsonProps) !== null && _a !== void 0 ? _a : []) { delete propsWithoutExcludedProps[prop]; } const serializedProps = serialize(propsWithoutExcludedProps); let mergedProps = Object.assign(Object.assign({}, serializedProps), (_b = props.excludedSuperjsonProps) === null || _b === void 0 ? void 0 : _b.reduce((acc, excludedProp) => { acc[excludedProp] = props[excludedProp]; return acc; }, {})); return (_jsx(SuperJSONComponent, { component: Component, props: mergedProps, children: props.children })); }; } //# sourceMappingURL=with-superjson.js.map