How to create unique Gatsby node ids

All Gatsby nodes need a unique id. Luckily for you, a Gatsby Source Plugin developer, you are not responsible for creating unique ids. You are only responsible for supplying a unique-within-your-universe-id to createNodeId. Gatsby is responsible for returning a unique node id.

exports.sourceNodes = async ({ actions, createNodeId }) => {
  const { createNode } = actions;

    id: createNodeId("unique-within-your-universe-id"),

    // More fields

In Gatsby Source YouTube oEmbed we use the YouTube id. It is unique across the YouTube universe.

All the best,
Queen Raae

PS: createNodeId is deterministic

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