Pubudu Jayasanka
Pubudu Jayasanka

Reputation: 1462

Array destructoring in React.js

I have implemented a hook that returns an array with two elements like below.

export function useSearchParams() {
 ..
 ../
return [searchParams, setSearchParams];

}

I only need to access this setSearchParams element in my component.

 const [{},setSearchParams] = useSearchParams();

This throws an es-lint warning when I add {} for the first parameter. What is the best practice on this? If I only want to access the second parameter?

Upvotes: 1

Views: 104

Answers (2)

soham Patel
soham Patel

Reputation: 66

you can just use

const [,setSearchParams] = useSearchParams();

Upvotes: 2

Tushar Shahi
Tushar Shahi

Reputation: 20431

You can do something like this:

const [,setSearchParams] = useSearchParams();

Example:

let arr = [1,3];
let [,ans] = arr;

console.log(ans);

Upvotes: 2

Related Questions