Socket
Socket
Sign inDemoInstall

gatsby-plugin-react-decorators

Package Overview
Dependencies
2
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    gatsby-plugin-react-decorators

1. Install the package


Version published
Weekly downloads
2.3K
increased by21.57%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Setup

  1. Install the package

npm install gatsby-plugin-react-decorators

  1. Configure the plugin in your local gastby-config.js file
// gatsby-config.js

const opts = require('gatsby-plugin-react-decorators').decoratorOptions;

module.exports = {
  plugins: [
    {
      resolve: "gatsby-plugin-react-decorators",
      options: {
        react: {
            options: opts.runtime | opts.ssr
        },
        reactDOM: {
            options: opts.runtime | opts.ssr | opts.enableProfiler
        }
      },
    }]
}

Note that the opts.enableProfiler option (enabled by default) will enable the React profiler (as if you had added the --profile option to gatsby build/gatsby develop, or manually specified react-dom/profiling as a webpack alias for react-dom).

  1. Register your local decorators

If you're using decorators during the server-side render process, add the following to your gatsby-ssr.js file:

// gatsby-ssr.js

import { registerDecorator } from 'webpack-decorators';

// This code can be executed immediately
const exampleDecorator = {
    createElement: function(originalFunc, ...args) {
        // Put your custom logic here...
        return originalFunc(...args);
    }
};

registerDecorator('react', exampleDecorator, 'createElement');

If you're using decorators during runtime (in the browser), add the following to your gatsby-browser.js file:

// gatsby-browser.js
import { registerDecorator } from 'webpack-decorators';

export const onClientEntry = () => {

    const exampleDecorator = {
        createElement: function(originalFunc, ...args) {
            // Put your custom logic here...
            return originalFunc(...args);
        }
    };

    registerDecorator('react', exampleDecorator, 'createElement');
};

Note:

You can register multiple decorators with multiple registerDecorator statements.

Version Notes

Package version 3.0 and up support React/React-Dom 17.0.1 and up.

Keywords

FAQs

Last updated on 30 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc