I want to redirect to index.html on clicking the div in react class component
i already having one on click function for passing value and also i tried all the ways
- history.push
- windows.location
- withRouter but nothing works
and because of class component history.push gives a error as it cannot be used in class component
This is my js code
import React, { Component } from 'react';
import axios from 'axios';
class Tweet extends Component {
constructor(props) {
super(props);
this.state = {
value: null,
};
this.handleClickHai = this.handleClickHai.bind(this);
this.handleClickHello = this.handleClickHello.bind(this);
}
handleClickHai(){
this.setState(state => ({
value: 'Hai'
}));
axios.get('/setvalue?value=Hi')
.then( function (response){
console.log(response)
})
.catch(function (error) {
console.log(error)
});
}
handleClickHello(){
this.setState(state => ({
value: 'Hello'
}));
axios.get('/setvalue?value=Hello')
.then( function (response){
console.log(response)
})
.catch(function (error) {
console.log(error)
});
}
render() {
return (
<div className="greet" >
<div className="hello" onClick={this.handleClickHello} >
<h4>Hello</h4>
</div>
<div className="hi" onClick={this.handleClickHai}>
<h4>Hi</h4>
</div>
</div>
);
}
}
export default Tweet;
when i click the hello div it will pass the value to variable and also i want it to redirect to html page anyone help me with the code