gatsby-plugin-prefix
Use prefix today, save time tomorrow
Table of Contents
Installation
npm install gatsby-plugin-prefix
Usage
- Register plugin
In gatsby-config.js
:
module.exports = {
plugins: [
...otherPlugins,
{
resolve: "gatsby-plugin-prefix",
options: {
tag: "tags",
category: "categories",
blog: "articles",
},
},
],
};
API
usePrefix
function() -> obj
This is a React hook that gives you access to the prefix objects that you declared when registering the plugin.
function MyComponent() {
const { tag, category, blog } = usePrefix();
console.log(tag);
console.log(category);
console.log(blog);
return <>{...}</>
}
Use Gatsby Node
This plugin creates a Prefix
Gatsby node type. When working inside Gatsby lifecycle (createPages
, sourceNodes
, etc), you can run a Gatsby GraphQL to get the prefix data:
query {
allPrefix {
nodes {
name
value
}
}
}
License
MIT