【发布时间】:2019-11-08 13:02:58
【问题描述】:
我需要画一些彩色方块,并使用道具来控制这些方块的颜色。
当前代码不起作用
import React from "react";
class SketchExample extends React.Component {
constructor(props) {
super(props);
}
render() {
const { color } = this.props;
return <div style={{ color: this.props.color, width: "36px", height: "36px" }} />; } }
export default SketchExample;
还有 app.js 文件
import React from "react";
import ReactDOM from "react-dom";
import SketchExample from "./SketchExample";
function App() {
return (
<div className="App">
<SketchExample color={{ r: "201", g: "112", b: "19", a: "1" }} />
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
哪一部分出了问题?谢谢。
【问题讨论】:
标签: javascript css reactjs