I'm using React Hooks in my SPA. I know how it works, but I have a doubt when declaring the hook, i.e., I'm using react-cookie
and the declaration of the hook is 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.
Is it possible to ignore these two vars
? I tried const [..., ..., removeCookie] = useCookies([]);
but this won't work.
Thanks in advance.
Only after the render is the useEffect call within the usePrevious Hook updated with the new value, 1 . This cycle continues, and in this way, you'll always get the previous value passed into the custom Hook, usePrevious .
React hooks are not required to return anything. The React documentation states that: We don't have to return a named function from the effect. We called it cleanup here to clarify its purpose, but you could return an arrow function or call it something different.
Hooks make React so much better because you have simpler code that implements similar functionalities faster and more effectively. You can also implement React state and lifecycle methods without writing classes.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With