I'm a software engineer with over 15 years of experience developing web and mobile applications. Follow my blog, and follow me on Pluralsight https://www.pluralsight.com/authors/marques-woodson
I don't know if I'd say one way is better than the other. I return arrays sometimes if there aren't a lot of objects being returned, but once I get more than 3 I would probably switch to returning an object. I also use a lot of Typescript, so defining the return type helps with not mixing up variables.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Wouldn't it be better to return an object from a custom hook rather than an array?
So instead of returning like this -
We could choose to return -
This way I don't have to worry about the position at which my
todos
or methodaddToDo
is accessible?I don't know if I'd say one way is better than the other. I return arrays sometimes if there aren't a lot of objects being returned, but once I get more than 3 I would probably switch to returning an object. I also use a lot of Typescript, so defining the return type helps with not mixing up variables.