I'm quite new to react router and I'm having few difficulties. I have no problems using history inside a component. Howver, I have a function outside the said component and it can't detect history. I tried alot of things but to no avail. It gives me a history is undefined
error
UserAvatar.js
import {withRouter} from "react-router-dom";
const signOut = (history) => {
console.log(history);
localStorage.removeItem("token");
localStorage.removeItem("user");
history.replace('/sign-in');
};
export class UserAvatar extends Component {
render() {
const content = (
<div>
<p>Content</p>
<Button className="sign-out" onClick={() => signOut(this.props.history)}>Sign-out</Button>
</div>
);
export default withRouter(UserAvatar, signOut)
any ideas would be of great help Thanks!