Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

history.createBrowserHistory is not a function - react js

I want to use history library but I got this message:

https://www.npmjs.com/package/history

TypeError: (0 , _history.createBrowserHistory) is not a function
[0]     at Object.<anonymous> (/Users/sm_emamian/Desktop/react js/shadyab/app/helpers/history.helper.js:3:30)

my helper:

import { createBrowserHistory } from 'history';

export const historyHelper = createBrowserHistory();

package.json:

"history": "^1.17.0",
like image 993
S.M_Emamian Avatar asked Apr 05 '18 16:04

S.M_Emamian


People also ask

How do you use createBrowserHistory in react?

Import creatBrowserHistory with curly brackets. It's exported as a named export. // history. js import { createBrowserHistory } from "history"; export default createBrowserHistory();

How do I import useHistory?

All we need to do is to call the useHistory hook inside a functional component: import { useHistory } from 'react-router-dom'; const App = () => { const history = useHistory(); const redirect = () => { history. push('/login'); } return ( <div> <h1>Hi there!


1 Answers

1.17.0 version has createHistory not createBrowserHistory check the link - https://www.npmjs.com/package/history/v/1.17.0

// using an ES6 transpiler, like babel
import { createHistory } from 'history'

// not using an ES6 transpiler
var createHistory = require('history').createHistory
like image 150
Waseem Raja Shaik Avatar answered Oct 10 '22 03:10

Waseem Raja Shaik