R
Reactiflux

help-js

✅ – Script – 13-00 Dec 1

SScript12/1/2022
is this a correct syntax const [response] = await tasks.createTask() Im familiar with the object destructuring method but this looks kinda weird
SS3BAS12/1/2022
yeah it's valid syntax
UUUnknown User12/1/2022
Message Not Public
Sign In & Join Server To View
SScript12/1/2022
oh but how does it work tho I tried testing it by creating a function to return an array ["response", "jason"] then I did const ["jason"] = function();` then console logged it and it kept on returning "response"
SS3BAS12/1/2022
The word that goes in the [] is the assigned variable name And it's based on the position
const [horse, tiger] = ["response", "jason"]
console.log(horse) // response
console.log(tiger) // jason
const [horse, tiger] = ["response", "jason"]
console.log(horse) // response
console.log(tiger) // jason
horse and tiger can be whatever you want, it's the name of the variable you are declaring
SScript12/1/2022
oh same way with useState so it doesnt matter what i name the first and second index, the first would always be the state variable then the second would always be what changes the state variable
SS3BAS12/1/2022
Yeah, because useState returns an array, the first element holding the current value and the second giving you the function that can update it
UUUnknown User12/1/2022
Message Not Public
Sign In & Join Server To View
SS3BAS12/1/2022
Which you are destructing
SScript12/1/2022
that makes sense thanks
UUUnknown User12/2/2022
3 Messages Not Public
Sign In & Join Server To View

Looking for more? Join the community!