Skip to main content
Community Plugin
View plugin on GitHub
See starters using this

Optional chaining support for Gatsby’s Babel config


It enables the optional chaining operator (a ?. b): see the TC39 proposal

How to install

Install the plugin and its dependencies :

npm i @bumped-inc/gatsby-plugin-optional-chaining @babel/core @babel/plugin-proposal-optional-chaining


yarn add @bumped-inc/gatsby-plugin-optional-chaining @babel/core @babel/plugin-proposal-optional-chaining

Add the plugin in gatsby-config.js:

module.exports = {
  plugins: [
    // other plugins

Examples of usage

const maybeObj = null;
const result = maybeObj?.value; // result: undefined

const actualObj = { value: 5 };
const betterResult = actualObj?.value // betterResult: 5