Giter Club home page Giter Club logo

Comments (6)

gnestor avatar gnestor commented on July 17, 2024 21

Is there any documentation/ or examples available demonstrating how to use the MJML React components directly?

from mjml.

iRyusa avatar iRyusa commented on July 17, 2024

Hello @alexcarruthers

Yes it should work, you can import any MjElement with :

import { elements } from 'mjml'

const { MjBody, MjSection, MjColumn, MjText }  = elements

Keep in mind that some fix aren't doable in react so you might need to use something like that : https://github.com/mjmlio/mjml/blob/master/src/mjml2html.js#L51-L6 to include media queries and most of outlook stuff. I'll try to do a release this week to expose them for advanced use of MJML

from mjml.

iRyusa avatar iRyusa commented on July 17, 2024

Is this ok for you @alexcarruthers can we close ? :)

from mjml.

jackcallister avatar jackcallister commented on July 17, 2024

@iRyusa Sorry to chime in on a closed issue but this doesn't seem to work as expected.

I can't get any of these elements to render:

render() {
    return (
      <elements.body>
        <elements.section>
          <elements.column>
            <elements.text>
              Some text which does not display
            </elements.text>
          </elements.column>
        </elements.section>
      </elements.body>
    )
  }

The HTML output:

<div data-reactroot=""><div class="mj-body" data-width="600"></div></div>

Taking away the body produces a table but no text rendering. Any help here would be much appreciated!

Also it looks like the imports have changed which is a bit awkward for use with React as a lot of the names are valid HTML so they need converting to be usable with JSX.

const { body, section, column, text } = elements
const Body = body
const Section = section
const Column = column
const Text = text

P.S Thanks a lot for the work you'll have put into this library. It's been fantastic! Also the reason for rendering with React is to show a live preview as close as possible to the final email HTML. Happy to help if possible.

from mjml.

iRyusa avatar iRyusa commented on July 17, 2024

Hi,

In a few days MJML 2 will be released (available on branch mjml-core), I believe that it should fix your issue of using MJML Components in a React context.

For your naming concern, all standard components will be prefixed with mj- to solve the possible conflict.

Keep in mind that MJML is more than a React based framework, a lot of fix for Outlook & many clients are done in a "post render". They aren't exposed in 1.X but, they will be in 2.X

from mjml.

jackcallister avatar jackcallister commented on July 17, 2024

Fantastic, looking forward to the release. Once again thanks for all the effort on this lib!

from mjml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.