react-app-rewire-decorators-legacy
v0.1.0
Published
Add decorators to your CRA application.
Downloads
14
Maintainers
Readme
This module add stage 1 decorators syntax and behavior.
Installation
yarn add -D react-app-rewire-decorators-legacy
OR
npm install --save-dev react-app-rewire-decorators
Usage
// config-overrides.js
const rewireDecorators = require("react-app-rewire-decorators-legacy");
module.exports = function override(config, env) {
config = rewireDecorators(config, env);
// other rewires...
return config;
};
or
// config-overrides.js
const { compose } = require("react-app-required");
const rewireDecorators = require("react-app-rewire-decorators-legacy");
module.exports = compose(
rewireDecorators
// other rewires...
);
Use cases
import {withRouter} from ‘react-router’
@withRouter
class MyComponent extends
@isTestable(true)
class MyClass {}
function isTestable(value) {
return function decorator(Target) {
return class extends Target {
isTestable = `isTestable: ${value}`;
};
};
}
class C {
@enumerable(false)
method() {}
}
function enumerable(value) {
return function(target, key, descriptor) {
descriptor.enumerable = value;
return descriptor;
};
}