我正在使用mongodb,表达和反应创建注册登录模块,但是在创建它时,我遇到了属性历史记录不存在错误:
属性'历史'不存在type'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
错误消息:
属性'历史'不存在type'readonly&amp;readonly&lt; {儿童?:reactnode;}>'。ts(2339(
我尝试了很多事情,但是这个错误不会发生
这应该运行
我猜你正在使用react路由器
如果是这样,您可以使用精确键入路由器将接口扩展到您的组件
import { RouteComponentProps } from 'react-router-dom';
interface userprops extends RouteComponentProps {}