-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(utils): allow object props to make it to the component #99
Conversation
Hi @robin-ray, and thank you for the idea. Unfortunately I am not sure giving more flexibility at the cost of unintentional mistakes is something we want to do with regards to the type safety on the Essentially what I am thinking is it may be reasonable to relax checks in const MyImage = () => {
const imgURL = { toString: () => "/path/to/some/resource" };
return <img src={imgURL} />;
}; will still throw an error. |
That's right! I'm using JavaScript for my components to avoid that issue. |
I'm all for having this be a compile-time error in TypeScript! My concern is about the runtime check. |
In that case I completely agree, it is not a good development experience for props to magically disappear. Just running CI checks now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me.
In general we are a little to strict about the props coming into components IMO. This is a related ticket that I think we should do in v4: #43
This might be a braking change since anything that was being silently made null
will now be passed through. Very unlikely though and it only breaks things that don't conform to the API so I think it's fine to add to v3. I've updated the title to a feat
though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thank you for the PR
🎉 This PR is included in version 3.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hello!
Summary
This PR changes the behavior of
convertPropValueToMjml
to give users of this library more flexibility, at the expense of allowing some unintentional mistakes to happen (ex: accidentally renderingsome-prop="[Object object]"
).Motivation
I have built a small library that uses objects and
toString()
to build up expressions that can be rendered to an MJML template. This works great for props on ordinary React HTML elements (this is a contrived example):React renders
<img src="/path/to/some/resource" />
for the snippet above.However, I have to explicitly convert the value to a string for it to pass through
mjml-react
:Without the explicit conversion, React will render
<mj-image />
becauseconvertPropValueToMjml
does not allowobject
props through (except fordangerouslySetInnerHTML
). It would be convenient ifmjml-react
components behaved more like React HTML components in this regard so that I don't have to do the extra string conversion.Thanks for considering this PR!