React devs - is there a best practice to rename properties from a hook? Say I have multiple useHooks: `const { data, isLoading } = useHook` Would you do this: `const { data: tx, isLoading: isTxLoading } = useHook` Or opposite: `const { data: tx, isLoading: TxIsLoading } = useHook` Or something else?
You could follow the `useState` pattern and actually return an array: `const [tx, isLoading] = useHook()`. Wouldn't recommend if it going to be a lot more properties coming back from the hook and would just go with local re-naming like you did on your last example.
I wouldn't call this a React best practice, necessarily, but I've always followed the convention that boolean variables are named "isFoo" or "hasFoo", so in this case, I'd do the former.
TxIsLoading is just worse naming convention imo isTxLoading sounds like a yes/no question which is what it should be as a boolean
The former (isTxLoading). Unfortunately, we can't use ? in variable names, which makes naming booleans so obvious and easy to read. In e.g. elixir it's very common to write txLoading?
Both names make sense. I think a large part of naming is convention and consistency. If all your codebase follows either of the patterns I think it is fine.
Another option is to skip destructuring altogether. Might be easier if you're working with multiple instances of the same hook.
not a react dev but these are the types of questions I usually ask chatgpt these days.
ChatGPT says… “There is no one "best" practice for renaming properties from a hook. The most important thing is to choose a naming convention that makes sense for the specific context of your application, and to be consistent in your use of it throughout your codebase.”