Javascript React JSX组件。Can';过流
使以下代码按预期工作:Javascript React JSX组件。Can';过流,javascript,reactjs,Javascript,Reactjs,使以下代码按预期工作: import Button from "./components/Button" import Excel from "./components/Excel"; import Logo from "./components/Logo"; import ReactDOM from "react-dom"; import React, {Component} from "react"; type Props = {}; type State = {}; class Par
import Button from "./components/Button"
import Excel from "./components/Excel";
import Logo from "./components/Logo";
import ReactDOM from "react-dom";
import React, {Component} from "react";
type Props = {};
type State = {};
class Parent extends Component<Props, State> {
constructor(props: Props) {
super(props)
}
triggerJson() {
this.excel.exportJSON();
}
triggerCsv() {
this.excel.exportCSV();
}
render() {
return (
<div>
<div style={{display: "inline-block", background: "purple"}}>
<Logo/>
</div>
<h1> Welcome to The App!^^!</h1>
<div>
<Button onClick={this.triggerJson.bind(this)}>Export JSON</Button>
<Button onClick={this.triggerCsv.bind(this)}>Export CSV</Button>
</div>
<Excel ref={excel => this.excel = excel} headers={headers} initialData={data} search={true}/>
</div>
);
}
}
及
我需要通过单击按钮调用Excel的
函数exportJSON
和exportCSV
。如何修改此代码以通过flow
控制
我得到的另一个错误是:
Cannot call ReactDOM.render with document.getElementById(...) bound to container because null [1] is incompatible with
Element [2].
我认为您只需要以下内容:
class Parent extends Component<Props, State> {
excel: whateverTheTypeOfThisShouldBe;
... (the rest of your class)
类父级扩展组件{
excel:这应该是什么类型的;
…(你们班的其他同学)
这将
excel
声明为您的父类的属性。您不必将函数绑定到该类吗?您可以在es6类中执行此操作。Pranay Tripathi,我该如何执行此操作?是的,excel:excel;
删除了前两个flow
错误。谢谢!最后一个在这里解释:
Cannot call ReactDOM.render with document.getElementById(...) bound to container because null [1] is incompatible with
Element [2].
class Parent extends Component<Props, State> {
excel: whateverTheTypeOfThisShouldBe;
... (the rest of your class)