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

Cannot use style.css_class_name syntax directly with React 15.3.1 #56

Closed
avesus opened this issue Aug 27, 2016 · 4 comments
Closed

Cannot use style.css_class_name syntax directly with React 15.3.1 #56

avesus opened this issue Aug 27, 2016 · 4 comments

Comments

@avesus
Copy link

avesus commented Aug 27, 2016

Warning: Failed prop type: Invalid prop className of type object supplied to ActiveComponent, expected string.

Have to type style.css_class_name + '' all the time...

I understand that that's some kind of React's limitations, because the object generated from csjs string has toString() method and should be treated by React as real string too.

What I doing wrong because I can't find the same issues from other people?

@rtsao
Copy link
Owner

rtsao commented Sep 23, 2016

Yeah, it appears the returned styles aren't satisfying React.PropTypes.string.

You could also do String(style.css_class_name) if that's more convenient. I might have to have a method on the returned styles object such as styles.getClassNames() which returns the string names of the classes as an object literal for all the styles. So that would be like:

typeof styles.css_class_name; // object
var classes = styles.getClassNames();
typeof classes.css_class_name // string

Or I might be able to use the String constructor and then add properties to that. But because typeof new String('foo') === 'object' I suspect that won't work.

@scott113341
Copy link
Collaborator

scott113341 commented Sep 23, 2016

@avesus, are you using react-router-active-component by any chance? That library is enforcing the className prop to be a string, as you can see here.

However, this is unique to that particular library. React does not require className to be a true string, as it will get cast to one.

@avesus
Copy link
Author

avesus commented Sep 23, 2016

@scott113341 thanks a lot! I have that problems mostly with that component.

@rtsao
Copy link
Owner

rtsao commented Sep 30, 2016

Formalized this here: #62

@rtsao rtsao closed this as completed Sep 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants