TypeError: Object(...) is not a function
See original GitHub issueHi!
I installed the package use-query-params: 1.1.7
but I’m getting this error When I used setQuery In react with ts, any sugestion?

App.tsx
import { BrowserRouter, Route } from 'react-router-dom';
import { QueryParamProvider } from 'use-query-params';
const App = (): React.ReactElement => {
return (
<BrowserRouter>
<QueryParamProvider ReactRouterRoute={Route}>
...
</QueryParamProvider>
</BrowserRouter>
);
})
index.tsx
import { useQueryParams, StringParam } from 'use-query-params';
const Test = (): React.ReactElement => {
const [query, setQuery] = useQueryParams({
foo: StringParam,
});
const { foo } = query;
return (
<button onClick={() => setQuery({ foo: 'test!' })}>Test</button>
)
};
I used
"use-query-params": "1.1.7",
"query-string": "6.13.2",
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:15 (6 by maintainers)
Top Results From Across the Web
JavaScript "Uncaught TypeError: object is not a function ...
Try to have the function body before the function call in your JavaScript file.
Read more >TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >TypeError: Object(...) is not a function · Issue #14484 - GitHub
What is the current behaviour? I have created react functional component and implement state full logic using useState method but it throws an ......
Read more >How to Handle JavaScript Uncaught TypeError: “x” is Not a ...
The Javascript error TypeError: "x" is not a function occurs when there is an attempt to call a function on a value or...
Read more >JavaScript: Uncaught TypeError: n is not a function
This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Getting this issue in ^1.2.0 @pbeshai
Problem only appears in productions builds in CRA
Fixed with installing query-string
Is there any reason that you actually need to allow it to depend on v6? I suspect the reason you are getting the wrong one is that when you installed initially it didn’t have any query-string available, so it installed the latest v6 as that is the latest version that met the spec. When you then installed 5.1.1 it saw that 6 was already installed, so it didn’t bother to change the one that use-query-params was using, because the one it had available met the requirements.
It will probably work if you remove your
node_modulesdirectory andyarn.lockand runyarnwith version 5 already specified in yourpackage.json, because then it will do the resolving before downloading anything.However, looking quickly through your code it doesn’t appear you are using anything from
query-stringthat would make it important to use v6, so overall you would be much better off by just declaring your dependency on^5.1.1and not worrying about 6 until after IE11 is EOL.Alternately, if you are really adamant about keeping v6 in the dependency you could leave it as a peer dependency and just add something to detect the situation and throw a more useful error message…
Something like:
You could also try something like https://www.npmjs.com/package/install-peerdeps to install peer dependencies automatically, but I’ve found that often leads to even weirder problems.