我试图使用流与react,我遵循了一些教程,但我无法解决这个错误,我的代码如下所示:
import React, { Component } from "react";
import { Link, withRouter } from "react-router-dom";
import { login } from "../../services/auth";
import api from "../../services/api";
import { getToken } from "../../services/auth";
import type { RouterHistory } from "react-router-dom";
type State = {
username: number,
password: string,
history: RouterHistory,
}
class Home extends Component < State > {
handleChange = this.handleChange.bind(this);
handleSignIn = this.handleSignIn.bind(this);
state = {
username: '',
password: '',
history: '',
};
错误出现在组件中的状态中。
编辑1:添加:
...
type Props = {/ * ... * /};
...
class Home extends Component <Props, State>
啊,真灵!但你想知道为什么吗?
发布于 2018-11-26 02:40:18
在反应流定义中,组件的泛型类型参数首先是道具,然后是状态。因此,正如您注意到的,首先提供道具类型,然后状态才是您想要做的。
https://stackoverflow.com/questions/53473053
复制相似问题