简体   繁体   English

React Hooks 中未使用的 var

[英]Unused var in React Hooks

I'm using React Hooks in my SPA.我在我的 SPA 中使用 React Hooks。 I know how it works, but I have a doubt when declaring the hook, ie, I'm using react-cookie and the declaration of the hook is const [cookies, setCookie, removeCookie] = useCookies([]);我知道它是如何工作的,但是在声明钩子时我有疑问,即,我正在使用react-cookie并且钩子的声明是const [cookies, setCookie, removeCookie] = useCookies([]); . .

In my case, I will only need the removeCookie var , I won't use the cookies and setCookie vars in my functional page, so lint complains about unused vars.就我而言,我只需要removeCookie var ,我不会在我的功能页面中使用cookiessetCookie vars ,所以lint抱怨未使用的 vars。

Is it possible to ignore these two vars ?是否可以忽略这两个vars I tried const [..., ..., removeCookie] = useCookies([]);我试过const [..., ..., removeCookie] = useCookies([]); but this won't work.但这行不通。

Thanks in advance.提前致谢。

Since you use array destructuring to make the assignments, you can ignore the items by adding commas without the variables/consts names:由于您使用数组解构进行赋值,因此您可以通过添加不带变量/常量名称的逗号来忽略这些项目:

const [,, removeCookie] = useCookies([]);

Example:例子:

 const [,, c] = [1, 2, 3] console.log(c)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM