这有效:
// @flow
import React, {Component} from 'react';
type Props = {};
class Delete extends Component<Props> {
targetElement: null | winndow.HTMLInputElement;
constructor(props: Props) {
super(props);
this.targetElement = null; // initialize to null
}
handleClick = (e: SyntheticEvent<> & {target: window.HTMLInputElement}) => {
this.targetElement = (e.target: window.HTMLInputElement).value;
};
render() {
return (
<input onClick={this.handleClick} value="hello" />
);
}
}
export default Delete;
Run Code Online (Sandbox Code Playgroud)
但这不是:
...
handleClick = (e: SyntheticEvent<> & {target: window.HTMLInputElement}) => {
this.targetElement = e.target.value;
};
...
Run Code Online (Sandbox Code Playgroud)
错误消息是:Cannot get …
我正在尝试构建一个呈现div显示错误的组件。
function ErrorDiv(props) {
return (
<Card>
<Typography>{props.message}</Typography>
</Card>
);
}
Run Code Online (Sandbox Code Playgroud)
我想设置<Card>背景颜色为palette.error.main,<Typography>字体颜色为白色的样式。
但是,我不确定如何访问主题颜色。是否有palette暴露的变量?或者我应该在我的主题创建模块中将单个颜色导出为字符串,然后导入颜色以供此处使用?