在打字稿中使用Redux获取初始状态

时间:2017-10-18 21:32:35

标签: reactjs typescript redux react-redux

我很难用打字稿,特别是微软的dotnet new react-redux。

我试图在启动时调用一个操作,以确定用户是否已登录,但打字稿不喜欢它并且我不理解错误。

这是布局代码:

import * as React from "react";
import { NavMenu } from "./NavMenu";
import { connect } from "react-redux";
import * as AuthStore from "../store/Auth";

type LayoutProps = typeof AuthStore.actionCreators;

class Layout extends React.Component<LayoutProps, {}> {
  componentDidMount() {
    this.props.getLoggedInUser();
  }
  public render() {
    return (
      <div className="container-fluid">
        <div className="row">
          <div className="col-sm-3">
            <NavMenu />
          </div>
          <div className="col-sm-9">{this.props.children}</div>
        </div>
      </div>
    );
  }
}

export default connect(null, AuthStore.actionCreators)(Layout) as typeof Layout;

这是造成问题的路线代码。

import * as React from "react";
import { BrowserRouter, Route } from "react-router-dom";
import Layout from "./components/Layout";
import Home from "./components/Home";
import FetchData from "./components/FetchData";
import Counter from "./components/Counter";
import SignUp from "./components/SignUp";
import SignIn from "./components/SignIn";

export const routes = (
  <Layout>
    <div>
      <Route exact path="/" component={Home} />
      <Route path="/counter" component={Counter} />
      <Route path="/fetchdata/:startDateIndex?" component={FetchData} />
      <Route path="/signup" component={SignUp} />
      <Route path="/signin" component={SignIn} />
    </div>
  </Layout>
);

我得到的错误是:

TS2322: Type '{ children: Element; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Layout> & Readonly<{ children?: ReactNode; }> & Re...'

error

0 个答案:

没有答案