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",
Import creatBrowserHistory with curly brackets. It's exported as a named export. // history. js import { createBrowserHistory } from "history"; export default createBrowserHistory();
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.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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With