Skip to content

ElegantStack/gatsby-plugin-babel-optional-chaining

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gatsby-plugin-babel-optional-chaining

Description

This plugin enables the optional chaining operator (a?.b) TC39 proposal for Gatsby.

How to install

Install the plugin and its dependencies:

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

or

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

Add the plugin to gatsby-config.js:

module.exports = {
  plugins: [
    // other plugins
    'gatsby-plugin-babel-optional-chaining',
  ],
}

Examples of usage

const obj = {
  foo: {
    bar: {
      baz: 42,
    },
  },
};

const baz = obj?.foo?.bar?.baz; // 42

const safe = obj?.qux?.baz; // undefined

// Optional chaining and normal chaining can be intermixed
obj?.foo.bar?.baz; // Only access `foo` if `obj` exists, and `baz` if
                   // `bar` exists

// Example usage with bracket notation:
obj?.['foo']?.bar?.baz // 42

About

Babel's optional chaining support for GatsbyJS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published