react-statics
v1.0.2
Published
Decorate React components with static properties
Downloads
460
Readme
react-statics
Decorate React components with static properties
Table of contents
Summary
When working with stateless functional components, or overriding default values on decorated components, applying statics can feel a bit boilerplate-y. This decorator centralizes the static property assignment, and allows for easy decorated composition.
Usage
Standard
import React from "react";
import statics from "react-statics";
const App = ({ foo }, { bar }) => (
<div>
{foo}: {bar}
</div>
);
export default statics({
contextTypes: {
bar: PropTypes.node.isRequired
},
displayName: "MySpecialApp",
propTypes: {
foo: PropTypes.string.isRequired
}
})(App);
Composed
import React from "react";
import { translate } from "react-i18next";
import { connect } from "react-redux";
import statics from "react-statics";
import { compose } from "redux";
const App = ({ foo }, { bar }) => (
<div>
{foo}: {bar}
</div>
);
export default compose(
statics({
contextTypes: {
bar: PropTypes.node.isRequired
},
displayName: "MySpecialApp",
propTypes: {
foo: PropTypes.string.isRequired
}
}),
translate(["namespace"]),
connect(({ reducer }) => reducer)
)(App);
NOTE: To ensure the values passed override any assigned by other composed decorators, place statics
last to execute in the composition chain.
Development
Standard stuff, clone the repo and npm install
dependencies. The npm scripts available:
build
=> run rollup to build developmentdist
filesclean
=> runclean:dist
,clean:es
, andclean:lib
clean:dist
=> remove all existing files in thedist
folderclean:es
=> remove all existing files in thees
folderclean:lib
=> remove all existing files in thelib
folderdev
=> run webpack dev server to run example app / playgrounddist
=> runsclean:dist
andbuild
lint
=> run ESLint against all files in thesrc
folderlint:fix
=> run ESLint against all files in thesrc
folder, fixing anything it can automaticallyprepublish
=> runsprepublish:compile
when publishingprepublish:compile
=> runlint
,test:coverage
,transpile:lib
,transpile:es
, anddist
test
=> run AVA test functions withNODE_ENV=test
test:coverage
=> runtest
but withnyc
for coverage checkertest:watch
=> runtest
, but with persistent watchertranspile:lib
=> run babel against all files insrc
to create files inlib
transpile:es
=> run babel against all files insrc
to create files ines
, preserving ES2015 modules (forpkg.module
)