Remember to validate your Gatsby Plugin options

When you make a Gatsby Plugin make sure to include a schema for your options. By doing so, Gatsby will verify that the plugin is configured correctly and stop everything if it is not!

Options Error

Users of your plugin will thank you for this immediate feedback. It saves them from reading through obscure undefined error messages or making sense of unexpected behavior when the reason is bad configuration.

Schema validation happens in the gatby-node.js file, using Joi to describe the schema.

// gatsby-node.js

exports.pluginOptionsSchema = ({ Joi }) => {
  return Joi.object({
    colors: Joi.array()
      .description("Array of hex color values"),
    intensity: Joi.string()
      .valid("regular", "light", "blizzard")
    duration: Joi.number()
      .description("Duration of snowfall in seconds"),
    season: Joi.object()
        start: new Date("December 1"),
        end: new Date("January 4"),
      .description("Start and end date for when snow should be activated"),

Example lifted from @raae/gatsby-plugin-let-it-snow.

All the best,
Queen Raae

PS: Would you be interested in a course/bootcamp on Gatsby Plugins?

Interested in more daily treasures like this one?
Sent directly to your inbox?

You might also be interested in...