When you return an object, you are forced to either use the object property name or need to alias it.
e.g.)
functionuseCustomState(){// logic ...return{state,setState};}functionApp(){const{state,setState}=useCustomState();// or you need to alias it to fit your business logicconst{state:price,setState:setPrice}=useCustomState();}
useState, useReducer and the ones you mentioned are so generic, so returning an object would put burden of such redundant aliasing as shown above.
IHMO, So it's a matter of a preference on how you want to consumer to consume your hooks.
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.
Generally when you create your hooks, you can return anything (array, object, symbol, etc).
Even in React documentation, useFriendStatus returns a boolean value.
The reason you see many hooks returning an array is to provide a way to a hook consumer to name the state & the state mutator the way you want.
JavaScript array destructuring syntax allows you to name each element.
When you return an object, you are forced to either use the object property name or need to alias it.
e.g.)
useState
,useReducer
and the ones you mentioned are so generic, so returning an object would put burden of such redundant aliasing as shown above.IHMO, So it's a matter of a preference on how you want to consumer to consume your hooks.