Questions tagged [urlsearchparams]

65 questions
7
votes
2 answers

Getting the "URLSearchParams.set is not implemented" error when trying to fetch data from my sanity backend using React Native

I am getting an error in my to react native project when pulling data from my sanity backend    this is the error URLSearchParams.set is not implemented This is where I am fetching he data  import {View, Text,SafeAreaView,Image,TextInput,ScrollView}…
5
votes
1 answer

How to prevent re-rendering when changing search param?

There is a small component in which, when you click on the button, the search param changes in the url. But when search param changes, the entire component is re-rendered, is it possible to make it so that only the url changes, without a re-render?…
Umbra
  • 53
  • 1
  • 4
4
votes
1 answer

How to use useSearchParams Hook with React Router v6

I am trying to implement a search parameter functionality to my React image search app. And, I have learned that I need to (can) use the useSearchParams Hook, but I am not sure how to make these changes. So, basically I want the URL to be something…
4
votes
1 answer

How type URLSearchParams in typescript to receive an object?

I have a function that receive via param an object and this object goes inside the URLSearchParams, after this, I make a toString() and get the answer below: const object = { name: 'Test', age: 20 }; function exampleFunction(objectExample)…
Lazarus
  • 75
  • 1
  • 1
  • 4
3
votes
1 answer

How to loop URLSearchParams?

I tried those two options, without any luck: let url = new URL(window.location.href); let key = undefined; for (let k of url.searchParams) { if(url.searchParams[k] == postID) { key = k; } } and let url = new…
János
  • 32,867
  • 38
  • 193
  • 353
2
votes
2 answers

Params without value in URLSearchParams?

I'd like to get an a=1&b=2&foo URL with URLSearchParams. Here's what I tried: new URLSearchParams([['a', 1], ['b', 2], ['foo']]).toString(); // Uncaught TypeError: Failed to construct 'URLSearchParams': // Failed to construct 'URLSearchParams':…
Robo Robok
  • 21,132
  • 17
  • 68
  • 126
2
votes
2 answers

How to log the result of "new URLSearchParams()"?

I am looking at this example on the google chrome docs. I am trying to console.log the variable params let url = new URL('https://example.com?foo=1&bar=2'); // or construct from window.location let params = new…
piraha
  • 65
  • 10
2
votes
2 answers

How to parse the complete link in the url query string?

URL: https://n9hon.csb.app?name=netflix&url=https://localhost?apikey=123&code=321 code: import { useLocation } from "react-router-dom"; function useQuery() { const {search} = useLocation(); const query = new URLSearchParams(search); …
Lin Du
  • 88,126
  • 95
  • 281
  • 483
2
votes
0 answers

URLSearchParams API always return an empty object from url parsing

My question is pretty simple. I try to use the URLSearchParams API. In my Google chrome browser console I got an empty object returned. I simply applied the example given here google example // Can also constructor from another…
jossefaz
  • 3,312
  • 4
  • 17
  • 40
2
votes
2 answers

How to remove only one of multiple key value pairs with the same key using URLSearchParams?

I have an url in this form: https://www.example.com?tag[]=mountain&tag[]=hill&tag[]=pimple Now I want to remove one of these, let's say tag[]=hill. I know, I could use regex, but I use URLSearchParams to add these, so I'd like to also use it to…
2
votes
2 answers

URLSearchParams fails to append array

Hi I'm having issues sending an array with URLSearchParams. My code is as follows: const worker = async(endpoint, method, parameters) => { let body; if (typeof parameters === 'object' && parameters !== null) { body = new…
Kex
  • 8,023
  • 9
  • 56
  • 129
1
vote
0 answers

Next.js 13 - Accessing search params from a deeply nested server component in the same route segment?

I know that search params are accessible in page component props, but can the deeply-nested, non-page server components inside the same route segment also access search params somehow? For example, let's assume a scenario. We have the following…
barkin
  • 179
  • 2
  • 12
1
vote
0 answers

Nextjs 13: How to show the loading ui when search params changes?

I have this component here: const MyComponent = (props: Props) => { const router = useRouter(); const searchParams = new URLSearchParams( Array.from(useSearchParams().entries()) ); const form = useForm({ defaultValues: { …
1
vote
1 answer

How to filter in React Router using searchParams

I am currently making a product filter website with react-router. I am able to get the searchParams, for example "color: black" but as soon as I select a different color it replaces the current selected value, but I would like to set multiple values…
1
vote
1 answer

findOne method, the url and the database have the same userId but cannot acces to mongoose database

enter image description here I use react for frontend. Then I do a find method everything works perfecly. Now the I do findOne method that's another story, I always got in catch and 404 error. router.get("/", auth, postCtrl.findFicheUser); // this…
1
2 3 4 5