Optional object chaining, but now
yarn add hitcher
import hitch from 'hitcher'
const myObj = {
person: {
name: {
first: 'Harry',
last: 'Fitz'
},
github: '@hjfitz'
}
}
const first = hitch(myObj, 'person', 'name', 'first')
Follows ...keys
in obj
, to find the value. Better than doing const foo = obj && obj[key] && obj[key][key2] && obj[key][key2][key3]
and so on.
Soon, one can use obj?.key?.key2?.key3
.
Optional object chaining - a new feature to land in ES!