Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript React JSX组件。Can';过流_Javascript_Reactjs - Fatal编程技术网

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)