Skip to content
the poor coder

require("history").createBrowserHistory` instead of `require("history/createBrowserHistory")`

Poor Man
Published
Reading time
1 min read
On this page

Answer:#

If you want to use the `history` package in your project, you can either import it like this: `require("history/createBrowserHistory")` or like this: `require("history").createBrowserHistory`. Both ways will work, but there is a slight difference between them.

Using `require("history/createBrowserHistory")`#

If you use the first method, you are importing the `createBrowserHistory` function directly from the `history` package. This means that you can only use this one function from the package and cannot access any other functions or variables that might be included in the package.

Text

const createBrowserHistory = require("history/createBrowserHistory");
const history = createBrowserHistory();
history.push("/about");

Using `require("history").createBrowserHistory`#

If you use the second method, you are importing the entire `history` package and then accessing the `createBrowserHistory` function from within it. This means that you can access all the other functions and variables that are included in the package, and not just the one you have imported.

Text

const history = require("history").createBrowserHistory();
history.push("/about");
const { createMemoryHistory } = require("history");
const memoryHistory = createMemoryHistory();

So, both methods are valid, but depending on your needs, one might be better suited than the other. If you only need one function from the package, you can use the first method to keep your code more concise. However, if you need to use multiple functions from the package, it might make more sense to import the entire package and access the functions from within it.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC