2017-08-15 11 views
0

Aus irgendeinem Grund, die onSubmit() Funktion kann ich nicht den Zustand isLoading setzen, obwohl ich ziemlich sicher bin, habe ich das gleiche in der Vergangenheit getan.Kann nicht Zustand auf reagieren Komponente

import * as React from 'react'; 
    import * as Redux from 'redux'; 
    const { connect } = require('react-redux'); 
    import { push } from "react-router-redux"; 
    import { Col, Jumbotron, Row, Well, Label, Button, FormGroup, FormControl } from 'react-bootstrap'; 
    import { ISession, IApplicationState } from "store"; 
    import './styles.scss'; 
    import { FeedComponent, Feed, StorageApiContext } from "api" 
    import { Content, ContentLoadingWrapper } from "components"; 


    interface IProfileUserPageProps { 
     session: ISession; 
     feed: Feed; 
     feedComponent: FeedComponent; 
    } 

    interface IProfileUserPageState { 
     isLoading: boolean; 
    } 


    @connect(
     (state: IApplicationState) => ({ 
      session: state.session.data, 
     }), 
     (dispatch: Redux.Dispatch<any>) => ({ 
      navigateToLogin:() => dispatch(push("/")), 
     }) 
    ) 

    export class ProfileUserPage extends React.Component<IProfileUserPageProps, IProfileUserPageState> { 

     constructor() { 
      super(); 
      this.state = { isLoading: false }; 
     } 

     componentWillMount() { 
      const { 
       session, 
      } = this.props; 

     } 

     onSubmit() { 
      this.setState = ({ isLoading: true }); 
      var inputValue = (document.getElementById("competitors-area") as HTMLInputElement).value; 
      const addTo: string[] = []; 
      inputValue.split("\n").forEach(company => { 
       addTo.push(company) 
      }); 
      const context = new StorageApiContext(); 
      this.props.session.user.Competitors = addTo; 
      context.Users.modify(this.props.session.user); 
     } 

Der Fehler, den ich erhalten ist:

ERROR in [at-loader] ./src/app/pages/profileUser/ProfileUserPage.tsx:38:28 
    TS2322: Type '{ isLoaded: boolean; }' is not assignable to type '{ <K extends "isLoaded">(f: (prevState: IProfileUserPageState, props: IProfileUserPageProps) => P...'. 
    Object literal may only specify known properties, and 'isLoaded' does not exist in type '{ <K extends "isLoaded">(f: (prevState: IProfileUserPageState, props: IProfileUserPageProps) => P...'. 

Antwort

2

setState() kein Objekt ist. Es ist die Funktion, so genannt zu werden:

this.setState({ isLoading: true }); 
+0

wow das war offensichtlich, danke – csiscs

Verwandte Themen