rescribet/link-redux

View on GitHub
src/hocs/link/wrapWithSubject.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import React from "react";

import { useLinkRenderContext } from "../../hooks/useLinkRenderContext";
import { SubjectProp } from "../../types";

export const wrapWithSubject = <P>(WrappedComponent: React.ComponentType<P & Partial<SubjectProp>>) => {
    const Comp = (props: P) => {
        const { subject } = useLinkRenderContext();
        const shared = { ...props, subject };

        return React.createElement(WrappedComponent, shared);
    };
    Comp.displayName = `linkSubject(${WrappedComponent.displayName || WrappedComponent.name})`;

    return Comp;
};