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

Export cx from @emotion/core #1225

Closed
FezVrasta opened this issue Feb 12, 2019 · 5 comments
Closed

Export cx from @emotion/core #1225

FezVrasta opened this issue Feb 12, 2019 · 5 comments

Comments

@FezVrasta
Copy link
Member

Hi, would you accept a PR that makes cx a top level export from @emotion/core?

Right now to use it you have to either use <ClassName> or the emotion package.

@Andarist
Copy link
Member

It's not a good idea within current design, because cx is eager whereas css from @emotion/core core is lazy-ish (it constructs an object, it doesnt insert the styles to the DOM, it also doesnt produce final class name - this happens in jsx).

cx just cant combine regular classes with css output outside of the render functions.

@FezVrasta
Copy link
Member Author

Thanks for the answer, does it mean that the cx exposed by emotion is different from the one of ClassNames?

@Andarist
Copy link
Member

Yes.

let cx = (...args: Array<ClassNameArg>) => {
if (hasRendered && process.env.NODE_ENV !== 'production') {
throw new Error('cx can only be used during render')
}
return merge(context.registered, css, classnames(args))
}

let cx = (...args) => {
return merge(cache.registered, css, classnames(args))
}

@FezVrasta
Copy link
Member Author

Oh ok I see, it makes sense then. Sorry for the waste of time!

@Eastonium
Copy link

Eastonium commented Aug 20, 2020

I'm currently trying to use vanilla emotion's cx as a direct replacement for the classnames library. I'm not using it on styles generated by emotion, just for strings + objects. Should I still switch to using the cx provided by the ClassNames component's render prop function? Honestly I'm hesitant because the ClassNames component with its render function is awfully bulky and ugly.

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

No branches or pull requests

3 participants