Reputation: 23
I am creating the signup sign-in module using mongodb, express and react but while creating this I encountered with property history does not exist error:
Property 'history' does not exist on type 'Readonly & Readonly<{ children?: ReactNode; }>'.ts(2339)
import React, { Component } from 'react'
import { login } from './userfunctions'
interface userprops{}
interface data{
email:string;
password:string;
errors: string;
}
//main class:
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
error message :
Property 'history' does not exist on type 'Readonly & Readonly<{ children?: ReactNode; }>'.ts(2339)
I have tried a lot of things but this error won't go
this should run
Upvotes: 1
Views: 4497
Reputation: 2878
i guess you are using react router
if so you can extend your interface with exact type what router will pass to your component
import { RouteComponentProps } from 'react-router-dom';
interface userprops extends RouteComponentProps {}
Upvotes: 5