# gatsby-plugin-react-decorators

> 1. Install the package

Latest version **3.0.0** (published 2024-01-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install gatsby-plugin-react-decorators
pnpm add gatsby-plugin-react-decorators
yarn add gatsby-plugin-react-decorators
bun add gatsby-plugin-react-decorators
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2024-01-30 |
| First published | 2020-05-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 22.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Chris Smith |
| Maintainers | smithc |
| Keywords | gatsby, plugin, react, react-dom, decorators, proxy, webpack, alias, interceptor |

## Links

- npm: https://www.npmjs.com/package/gatsby-plugin-react-decorators
- Repository: https://github.com/smithc/gatsby-plugin-react-decorators
- Homepage: https://github.com/smithc/gatsby-plugin-react-decorators#readme
- Issues: https://github.com/smithc/gatsby-plugin-react-decorators/issues
- npm.io page: https://npm.io/package/gatsby-plugin-react-decorators

## Dependencies (2)

- [webpack-decorators-react](https://npm.io/package/webpack-decorators-react.md) 0.0.4
- [webpack-decorators-react-dom](https://npm.io/package/webpack-decorators-react-dom.md) 0.0.4

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2024-01-30
- 2.0.0-beta.2 — 2022-03-22
- 1.0.0 — 2022-03-22
- 2.0.0-beta.1 — 2022-03-22
- 1.0.0-beta.2 — 2021-12-20
- 1.0.0-beta.1 — 2021-12-17
- 0.0.4 — 2020-06-25
- 0.0.3 — 2020-06-24
- 0.0.2 — 2020-05-24
- 0.0.1 — 2020-05-23

## README

# Setup

1. Install the package

`npm install gatsby-plugin-react-decorators`

2. 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`).

3. 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.

---
_Source: https://npm.io/package/gatsby-plugin-react-decorators · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
