Uploaded image for project: 'Magnolia Frontend Helpers'
  1. Magnolia Frontend Helpers
  2. MGNLFE-170

Use HOC for Magnolia property mapping (HA)

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Outdated
    • Neutral
    • None
    • None
    • None
    • None

    Description

      I created a Higher order component (HOC) to use with React. It is a reusable function that replaces the generated wrapper/builder from the HA generator. I don't see where the ha-cli project is hosted, so can't create a PR for it, but here is my code:

       

      export function withMgnlProps<P extends object>(
        Component: React.ComponentType<P>
      ): React.FC<P> {
        const WithMgnlProps = (props: PropsWithChildren<P>) => {
          const transformed = transformNode({ ...props });
          return <Component {...transformed} />;
        };
        const displayName = Component.displayName || Component.name || "Component";
        WithMgnlProps.displayName = `WithMgnlProps(${displayName})`;
        return WithMgnlProps;
      }

      Checklists

        Acceptance criteria

        Attachments

          Activity

            People

              stas Senol Tas
              mwienk Mark Wienk
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Checklists

                  Task DoD