React 书写小技巧
Props 默认值为 “True”
<MyTextBox autocomplete />
<MyTextBox autocomplete={true} />展开运算符
const props = {a:1, b:2};
<Control {...props}/><Control a={props.a} b={props.b}>const Button = props => {
const { kind, ...other } = props;
const className = kind === "primary" ? "PrimaryButton" : "SecondaryButton";
return <button className={className} {...other} />;
};
const App = () => {
return (
<div>
<Button kind="primary" onClick={() => console.log("clicked!")}>
Hello World!
</Button>
</div>
);
};最后更新于