Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Strategy for associating styles to components rather than at the parent level? #57

Open
Open
Strategy for associating styles to components rather than at the parent level?#57
Labels
questionFurther information is requested

Description

I have a base template component that i pass my components to and render them inside MjmlBody:

{styles} {mediaQueryStyles} {children} ); };">const BaseEmailTemplate = ({ children }) => {
const styles = readFileSync(resolve(__dirname, '../../assets/styles.css')).toString();
const mediaQueryStyles = readFileSync(resolve(__dirname, '../../assets/mediaQueries.css')).toString();

return (


{styles}
{mediaQueryStyles}


{children}


);
};

So I'm reading in css files and rendering the styles in MjmlHead, much like your example. For media queries, each of my templates includes ALL the styles, even styles targeted to components that a given template does not include. Since some email clients clip emails over a certain size, I want to only include styles that are relevant to the components included in a given template. Additionally, if I delete a component I want all its style definitions to go with it.

I'm wondering if you have any strategies for moving css to the component level so that only the styles associated with the children are rendered in head. Like ideally i'd like my components organized like this, with css tied to each component:

components/
BaseEmailTemplate/
BaseEmailTemplate.jsx
index.js
styles.css
Button/
Button.jsx
index.js
styles.css

Thanks for any tips.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions