#Yes, there is! 🍾
Yes, there is! 🍾
Optional chaining is in stage 4 and this enables you to use the user?.address?.street
formula.
If you can't wait the release, install @babel/plugin-proposal-optional-chaining
and you can use it.
Here are my settings which works for me, or just read Nimmo's article.
// package.json
{
"name": "optional-chaining-test",
"version": "1.0.0",
"main": "index.js",
"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "7.2.0",
"@babel/core": "7.2.0",
"@babel/preset-env": "^7.5.5"
}
...
}
// .babelrc
{
"presets": [
[
"@babel/preset-env",
{
"debug": true
}
]
],
"plugins": [
"@babel/plugin-proposal-optional-chaining"
]
}
// index.js
console.log(user?.address?.street); // it works