-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
shouldForwardProp in styled component #900
Comments
I think it isn't intentionally different, just native version of emotion is much newer than the version for the web and some differences might still be there, they should be unified though - as much as it's possible. We are happy to accept a PR handling custom shouldForwardProp. |
Sure, I can take a look at it. Maybe this would also be a good opportunity to unify the shouldForwardProp API and add documentation for it, if the implementation in @emotion/native works. |
The documentation is already added on master, it might not be released yet though as master contains v10-beta code currently. |
Could you post a link to the documentation for |
Oh, it's actually not merged into the master yet. Sorry for the confusion. You can check it out here https://github.com/emotion-js/emotion/pull/799/files#diff-e8ee253d6b88874fa7b359247bf59aa1R158 |
Thank you! |
This issues makes |
Implementing this is not overly complex - I encourage anyone interested in this feature to prepare a PR for this. |
I've implemented this in #1642 and it's going to be released in v11. |
emotion
version: 9.2.9react
version: 16.5.0Relevant code.
What you did:
I'm using react-native and react-testing-library together with react-native-web to test my components.
I added
{ shouldForwardProp: isPropValid }
to my styled components in react native to prevent the propisColored
from being forwarded.What happened:
Using the setup described above, I noticed that the prop
isColored
is being forwarded. The following error message will be displayed:Warning: React does not recognize the isColored prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase iscolored instead. If you accidentally passed it from a parent component, remove it from the DOM element.
Problem description:
It seems like
shouldForwardProp
isn't being called in @emotion/native. I tried passing aconsole.warn
to see ifshouldForwardProp
will be called, but nothing will be logged.Suggested solution:
@emotion/native uses
createStyled
from @emotion/primitives-core:emotion/packages/native/src/styled.js
Lines 1 to 7 in 7a4ff8e
primitives-core has a default implementation for
shouldForwardProp
:emotion/packages/primitives-core/src/styled.js
Lines 7 to 16 in 7a4ff8e
It seems like @emotion/native doesn't override this default implementation. It should provide an API to pass
shouldForwardProp
as option.Or maybe there is an API for it which isn't documented, or I can't find the documentation, or I can't find a way to do it in the emotion package code.
There is a discussion regarding this in the PR for @emotion/native: https://github.com/emotion-js/emotion/pull/759/files#r204662931
But to be totally honest, I don't understand why the API is intentionally different in comparison to @emotion/styled-base:
emotion/packages/styled-base/src/index.js
Lines 20 to 34 in 7a4ff8e
The text was updated successfully, but these errors were encountered: