-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
class vs className consumption #942
Comments
You can use The |
So if I wanted to make a component that's consumable by both React and Preact, it would be best to check for both properties? |
|
Sure, but devs that use Preact get the recommendation to use So I'm wondering if I should use some pattern like this:
|
This is one of the things Here's a tiny plugin for Preact that makes import { options } from 'preact';
const classNameDescriptor = {
enumerable: true,
configurable: true,
get() { return this.class; },
set(value) { this.class = value; }
};
let old = options.vnode;
options.vnode = vnode => {
let a = vnode.attributes;
if (a && a.class) {
Object.defineProperty(a, 'className', classNameDescriptor);
}
if (old) old(vnode);
}; |
I'm running into a classnames issue with sass modules in Preact:
The specified margin-bottom css does not get applied, any ideas? |
@BODAZ you need to reference it as // Card component
import { h, Component } from "preact";
import cx from "classnames";
import style from "./style";
export const Card = () => {
return (
<div class={style.card}>
<div class={cx(style.image, style['image-item'])} />
<div class={style.body} />
</div>
);
};
// in style.scss
.card {
.image-item {
margin-bottom: 23px;
}
} Better to post these types of unrelated questions on Slack or StackOverflow btw. |
@developit Agree, I think this belongs into |
Just destructure-rename it: function InnerView({class: className}) {/* ... */} |
After reading #103
I would think that this would work:
In componentB,
className
is undefined when componentA passesclass
as the prop (the preact recommendation), whereas in componentBthis.props.class
does equal "yyy"In my understanding, in componentB, I should be able to use
this.props.className
as well asthis.props.class
regardless of how the prop is passed in componentA. Am I under the wrong assumption?The text was updated successfully, but these errors were encountered: