Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

I figured out how to reuse the component class implementations from MDC directly in React #4

Closed
@jamesmfriedman

Description

@jamesmfriedman

@lynnjepsen, I know I've been blowing you up on discord a bit, but I had to share this.

This is currently hacked together, but the fact that it works is crazy. I found a way to import the actual component class from MDC web and directly use it in React.

  • I import the class
  • Pass it to an HOC
  • I create a new React Component
  • I copy the MWC component class descriptors over to the new class
  • I handle the DOM refs in a way that reflects the way the MDC component expects them
  • The only things I need to specify at this point are things that work a bit different in react like setting classes and a syncWithProps function which can handle the react render cycle.
  • It is currently hacky as hell, but I thought about this an hour ago and I'm still in shock it actually works.

Check it out

  • Don't mind all the code in the commit just look at base/MDCFoundation and IconToggle/index.
  • npm run storybook, navigate to IconToggle

rmwc/rmwc@17cdee6

What does this mean?
I don't have to reimplement a single foundation adapter! I can use all of the ones already written in MWC web with minimal tweaks. I need to work through this more to find the edge cases and do a real implementation, but I'm pretty stoked right now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions