问题描述
我从 react 切换到 preact,但我自己的组件没有成功渲染,可能是因为样式
有人可以帮我吗?
//MyComponent.js
import style from "./style.css";
let Component = () => (
<div style={style.home}>
<p>How are you today?</p>
</div>
);
export default Component;
和
//style.css
.home {
margin: 56px 20px;
width: 100%;
}
解决方法
CSS 模块加载器返回您应该分配给 class
属性而不是 style
的类名。
这是修改后的代码。
//MyComponent.js
import style from "./style.css";
let Component = () => (
// Use class and not style
<div class={style.home}>
<p>How are you today?</p>
</div>
);
export default Component;