Skip to content
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

Exporting multiple objects while using withStyles #134

Open
maharshi-roy opened this issue Mar 28, 2018 · 2 comments
Open

Exporting multiple objects while using withStyles #134

maharshi-roy opened this issue Mar 28, 2018 · 2 comments
Labels

Comments

@maharshi-roy
Copy link

maharshi-roy commented Mar 28, 2018

Is it necessary that the component to which withStyles has been applied be exported as default?
If not, how can I export multiple components after applying withStyles on each of them?
i.e. I'm trying to do something like -

class comp1 extends React.Component{....} 
withStyles(styles1)(comp1)
class comp2 extends React.Component{....}
    withStyles(styles2)(comp2)
    module.exports = {
         comp1 : comp1,
         comp2: comp2
    };

But ,it's not working..

@noratarano
Copy link
Collaborator

noratarano commented Mar 28, 2018

Hey @Strategist-Roy! Thanks for reaching out. In the code you provided above, you’re only exporting the components that are not wrapped with withStyles. withStyles will return a new component, and that’s what you want to export. You want to do something more like:

class PureComp1 extends React.Component {}
class PureComp2 extends React.Component {}

const Comp1 = withStyles(styleFn1)(PureComp1);
const Comp2 = withStyles(styleFn2)(PureComp2);

export { Comp1, Comp2 };

This will work. Let me know how it goes!

@MrStLouis
Copy link

Brilliant. I was so focused on keeping my original class name that I never thought of aliasing it like that. Saved me an hour easy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants