react-email icon indicating copy to clipboard operation
react-email copied to clipboard

Support for props in the preview app

Open guillaumelachaud opened this issue 2 years ago • 6 comments

Hi!

It would be great if the preview app could be used to edit props of a specific email. That could be useful to test out edge cases with long values, different alphabets,...

Would also be nice if we could supply default values only meant to be used for the preview app.

guillaumelachaud avatar Jan 24 '23 00:01 guillaumelachaud

I support this suggestion, however there is a solid solution for the default value problem.

You can destructure your prop object and add whatever defaults you want.

When the preview app renders the email, the defaults are used:

interface EmailProps {
  /**
   * User's first name
   */
  firstname: string;
  /**
   * User's last name
   */
  lastname: string;
}

const Email: React.FC<EmailProps> = ({
  firstname = "John",
  lastname = "Doe",
}) => {
  return (
    <Html>
      <Section>
        <Text>
          Hello {firstname} {lastname}
        </Text>
      </Section>
    </Html>
  );
};

image

Best part of this solution is that even though you supply defaults and the preview app doesn't throw an error, the typescript server does: image

ImBaedin avatar Jan 24 '23 04:01 ImBaedin

This is a SUPER interesting feature.

An inspiration that came to mind was Microlink Cards: https://cards.microlink.io/editor?preset=workos

CleanShot 2023-01-23 at 22 43 03@2x

zenorocha avatar Jan 24 '23 06:01 zenorocha

Great point about the default values @ImBaedin, I feel like we should update all demos to contain that pattern. Do you want to send a PR?

zenorocha avatar Jan 24 '23 06:01 zenorocha

Great point about the default values @ImBaedin, I feel like we should update all demos to contain that pattern. Do you want to send a PR?

You're talking about these demos right? If so, sounds like fun 😊

ImBaedin avatar Jan 24 '23 07:01 ImBaedin

Yep ;)

zenorocha avatar Jan 24 '23 07:01 zenorocha

Yep ;)

#377

ImBaedin avatar Jan 25 '23 05:01 ImBaedin