Reactiflux
Reactiflux

help-js

Root Question Message

Script
Script12/1/2022
is this a correct syntax
const [response] = await tasks.createTask()

Im familiar with the object destructuring method but this looks kinda weird
S3BAS
S3BAS12/1/2022
yeah it's valid syntax
Message Not Public

Sign In and Join Server To See

12/1/2022
Script
Script12/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 didconst ["jason"] = function();`
then console logged it and it kept on returning "response"
S3BAS
S3BAS12/1/2022
The word that goes in the [] is the assigned variable name
S3BAS
S3BAS12/1/2022
And it's based on the position
S3BAS
S3BAS12/1/2022
const [horse, tiger] = ["response", "jason"]
console.log(horse) // response
console.log(tiger) // jason
S3BAS
S3BAS12/1/2022
horse and tiger can be whatever you want, it's the name of the variable you are declaring
Script
Script12/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

Solution Message

S3BAS
S3BAS12/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
Message Not Public

Sign In and Join Server To See

12/1/2022
S3BAS
S3BAS12/1/2022
Which you are destructing
Script
Script12/1/2022
that makes sense
Script
Script12/1/2022
thanks
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy