反应本机错误:属性“历史”不存在

时间:2019-07-09 11:31:16

标签: reactjs typescript react-native react-router

我正在使用mongodb创建注册登录模块,表达并做出反应,但是在创建该模块时我遇到的属性历史记录不存在错误:

  

类型'Readonly&Readonly <{子代?:ReactNode; }>'。ts(2339)

import React, { Component } from 'react'
import { login } from './userfunctions'

interface userprops{}
interface data{
    email:string;
    password:string;
    errors: string;
}

//主类:

class Login extends Component<userprops, data> {
  constructor(props: userprops) {
    super(props)
    this.state = {
      email: '',
      password:'',
      errors: ''
    }
this.onChange = this.onChange.bind(this) //binding the function
this.onSubmit = this.onSubmit.bind(this)  //binding the function
  }
  onChange(e:any) {  //on change function
    this.setState({ email: e.target.value })
  }
  onSubmit(e:any) {   //on submitting the form in render function this function will fire
e.preventDefault()
const user = {
email: this.state.email,
      password: this.state.password
    }


    login(user).then(res => { //I had created login function in another component
      if (res) {
         this.props.history.push(`/profile`)  //this line is giving error
      }
    })

  }
render() {
   //rendering data
}

export default Login

错误消息:

  

类型'Readonly&Readonly <{子代?:ReactNode; }>'。ts(2339)

我尝试了很多事情,但是不会出错

这应该运行

1 个答案:

答案 0 :(得分:0)

我猜你在用反应路由器

如果这样,您可以使用确切的类型扩展接口,路由器将传递给您的组件

import { RouteComponentProps } from 'react-router-dom';

interface userprops extends RouteComponentProps {}