const obj = {
foo: {
bar: {
baz: 42,
},
},
};
const baz = obj?.foo?.bar?.baz; // 42
const safe = obj?.qux?.baz; // undefined
Provide the optional-chaining babel plugin in gatsby, just install and put in gatsby-config.
$ npm i gatsby-optional-chaining
or
$ yarn add gatsby-optional-chaining
Add the plugin to your gatsby-config.js
.
module.exports = {
plugins: [
`gatsby-optional-chaining`,
]
}