Faire / mjml-react

React component library to generate the HTML emails on the fly
https://www.npmjs.com/package/@faire/mjml-react
MIT License
375 stars 16 forks source link

No Render method in this mjml-react npm module #100

Closed Jarrodsz closed 1 year ago

Jarrodsz commented 1 year ago

I tried debugging this for 30 minutes to no avail. I have existing render method for rendering mjml mails converted from mjml-react which I still depend on but want to remove this dependency.

import React from "react";
import Layout from "app/core/mails/Layout";
import { render } from "mjml-react";

import { MjmlColumn, MjmlText } from "@faire/mjml-react";

interface Mail {
  showHeader?: boolean;
  showFooter?: boolean;
  user: any;
}

export default function renderWelcomeEmail({
  user,
}: Mail) {
  return render(
    <Layout>
      <MjmlColumn>
        <MjmlText>Hi {user.id}</MjmlText>
        <MjmlText>welcome</MjmlText>
      </MjmlColumn>
    </Layout>,
    { validationLevel: "soft" }
  );
}

The problem here is there seems to be no render method or replacement on @faire/mjml-react

Is there a workaround for this or is there a hidden method on @faire/mjml-react that i missed to render my content like this?

Jarrodsz commented 1 year ago

The problem is I need a replacement for this line:

import { render } from "mjml-react"; to be able to remove it from my npm package 😞

emmclaughlin commented 1 year ago

Hi @Jarrodsz, I believe the replacement you are looking for is:

import { render } from "@faire/mjml-react/utils/render"

See here: https://github.com/Faire/mjml-react/blob/main/src/utils/render.ts#L14

We moved it out of the main package export, as it requires html-minifier as a dependency but we recognize not all users want to have this minification. We now recommend writing your own render function in the readme as it seems users are split between mjml and mjml-browser as well. But we kept the existing render function for ease of migrating to v3, just moved it.

Jarrodsz commented 1 year ago

Great thank you for the writeup! Could not find the right method in the package itself this works