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

[CSS Modules] Multiple binds in same component? #83

Closed
kevinSuttle opened this issue May 20, 2016 · 2 comments
Closed

[CSS Modules] Multiple binds in same component? #83

kevinSuttle opened this issue May 20, 2016 · 2 comments

Comments

@kevinSuttle
Copy link

kevinSuttle commented May 20, 2016

Is the following possible? I cannot seem to get it to work.

let inputClasses = classNames.bind(inputStyles);
let labelClasses = classNames.bind(labelStyles);
let inputClassList = inputClasses({
  inputField: true,
  preValidated: this.state.focused,
});

let validationMessageClassList = labelClasses({
  errorLabel: true,
  postValidated: !this.state.focused,
});
<TextInput className={inputClassList} />
<ErrorLabel className={validationMessageClassList} />

For some reason, the styles appear in React Dev Tools, but not in the DOM.
Look for postValidate in the following screenshots. It only appears in RDT.

screen shot 2016-05-20 at 5 07 37 pm

screen shot 2016-05-20 at 5 07 57 pm

@koulmomo
Copy link

koulmomo commented May 20, 2016

try

let inputClasses = classNames.bind(null, inputStyles);
let labelClasses = classNames.bind(null, labelStyles);

function.prototype.bind takes thisArg as a first parameter

@kevinSuttle
Copy link
Author

That actually broke it.

How I fixed it:
made sure the presentational components did not have classNames, except for props.className. Then, in the container component, I just used the syntax above.

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

2 participants