-
-
Notifications
You must be signed in to change notification settings - Fork 161
Process className key in a destructured object #44
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
Comments
How is this marked as an enhancement ? That's clearly a bug and is a show stopper one. We want to use HOCs which sent down some classnames like so: The styleName in // withWarning.js
import 'styles.scss'; // has inside a class .warning
export default Component => ({warning, ...props}) => {
let styleNames = '';
if (warning) {
styleNames = 'warning';
}
return <Component {...props} styleName={styleNames}/>;
}; At // /prettyText.js
import withWarning from './withWarning';
import 'styles.scss'; // has inside a class .pretty
const Text = props => {
return <div {...props} styleName='pretty' />;
};
export default withWarning(Text); Ending up with something like so: // index.js
import TextWithWarning from './text.js';
ReactDOM.render(<TextWithWarning warning>Error</TextWithWarning>);
// Expected: <div class='withWarning__warning__er3432 prettyText__pretty__ty3342'>Error</div>
// Got: <div class='prettyText__pretty__ty3342'>Error</div> |
@giorgosavgeris Dunno about this being a show-stopper -- this issue is very easy to workaround. While slightly unintuitive, I usually do something like this: import styles from './MyComponent.module.css';
const { whatever, ...otherProps } = props;
const className = `${styles.wrapper} ${otherProps.className}`
<div {...props} className={className}>
<p styleName="style-name-still-works-too">...</p>
</div> |
🎉 This issue has been resolved in version 5.2.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
The output looks like this:
The
className
from props is overwritten, but I would like it to be included in the finalclassName
assignment sinceclassName
was not specified on thediv
. I thinkgetClassNames
should accept a third parameter: every object that is destructured before thestyleName
attribute.getClassNames
would iterate through these objects looking forclassName
, then include whicheverclassName
appears last in the list of objects in the finalclassName
assignment.Something like this:
The text was updated successfully, but these errors were encountered: