2017-08-15 1 views
0

Pour une raison quelconque, la fonction onSubmit() Je ne peux pas définir l'état de isLoading même si je suis pratiquement sûr d'avoir fait la même chose par le passé.Impossible de définir l'état sur le composant de réaction

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); 
     } 

L'erreur que je reçois est:

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...'. 

Répondre

2

setState() est pas un objet. Il est fonction d'être appelé comme ça:

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

wow c'était évident, merci – csiscs