2 ms·
Pedantic nit: [ readRequest, requestRead ] reminds me of one of my least favourite nitfalls from Django: FileField and FieldFile. Yes, the names make sense.
by Waterluvian 5y ago
Pedantic nit: [ readRequest, requestRead ] reminds me of one of my least favourite nitfalls from Django: FileField and FieldFile. Yes, the names make sense. But human brains mash these things up so regularly that I never seem to be able to permanently remember what's what. I'm always triping on them.
This also brings me to something I've been wrestling with a bit: Array unpacking allows you to pick your own variable names, but you also generally have to unpack everything if you want some later variables. Order matters. I find this is not very self-documenting and is less fun for autocomplete.
Object unpacking lets you pick and choose what pieces you need from the hook's interface, and they come pre-named, which is good but sometimes bad.
I think I'm settling on Object unpacking being the better pattern for my tastes.
- depressedpanda 5y agoI would argue that object unpacking is superior unless you have something similar to useState, where you only return two variables, and you know you'll never need the second variable without the first (which in practice may be very difficult to know beforehand, as requirements change). Object unpacking also allows you to alias the variable names, though it's slightly more verbose: `const { foo: newName } = someThing()`. You can also choose to forgo unpacking entirely and just use the natural namespacing returning an object would provide: const thing = someThing() thing.foo() thing.bar()