The plugin provides an easy integration for the [React Client SDK](https://github.com/splitio/react-client) of [Split.io](https://www.split.io/) to use Feature Flags within GatsbyJS.
npm install gatsby-plugin-splitioThe plugin provides an easy integration for the React Client SDK of Split.io to use Feature Flags within GatsbyJS.
with yarn yarn add gatsby-plugin-splitio
with npm npm install --save gatsby-plugin-splitio
1. Get an account at Split.io
2. Get the authorizationKey in the app of Split.io
Admin Settings -> API Keys -> Javascript SDK (browser)
3. Get the key at
Admin Settings -> All Environments
Add the plugin with the respective options in your gatsby-config.js:
``javascriptgatsby-plugin-splitio
module.exports = {
plugins: [
{
resolve: ,
options: {
authorizationKey: ,
key: ,`
},
},
],
}
Place the TestToggle component into your components directory and use it in one of your pages. Rename YOUR_FEATURE to one of the feature names you added to your Split account.
`jsx
// TestToggle.js
import React from 'react'
import { SplitTreatments } from 'gatsby-plugin-splitio'
const feature = 'YOUR_FEATURE'
const TestToggle = () => (
{({ treatments }) => {
const treatment = treatments[feature].treatment
return (
<>
{treatment === 'on' ? (
) : (
)}
>
)
}}
)
function VariantOne({ treatment, feature }) {
return (
, backgroundColor: HONEYDEW }}>
Component: Variant One
Feature: {feature} with{' '}
Split.io
{' '}
is {treatment}
function VariantTwo({ treatment, feature }) {
return (
, backgroundColor: LAVENDERBLUSH }}>
Component: Variant Two
Feature: {feature} with{' '}
Split.io
{' '}
is {treatment}
export default TestToggle
``
More detailed information describes the help page of Split.io
The plugin exposes these named exports:
- SplitTreatments
- SplitClient
- SplitContext
- useTreatments
- useManager
- useTrack
- withSplitTreatments
- withSplitClient
Please reach out for any question regarding this plugin or open a PR if you would like add or amend something.