A babel plugin to generate args of recompose.onlyUpdateForKeys
from flow type.
It is intended to be an alternative to recompose.onlyUpdateForPropTypes
for flow type.
In
// @flow
import React from 'react';
import { compose, onlyUpdateForKeys } from 'recompose';
export default compose(
onlyUpdateForKeys(), // without args
)(function Foo(props: { foo: string, bar: number }) {
const { foo, bar } = props;
return (
<div>{foo}-{bar}</div>
);
});
Out
// @flow
import React from 'react';
import { compose, onlyUpdateForKeys } from 'recompose';
export default compose(
onlyUpdateForKeys(['foo', 'bar']), // with args
)(function Foo(props: { foo: string, bar: number }) {
const { foo, bar } = props;
return (
<div>{foo}-{bar}</div>
);
});
$ npm install --save-dev babel-plugin-flow-onlyupdateforkeys
.babelrc
{
"plugins": ["flow-onlyupdateforkeys"]
}
$ babel --plugins flow-onlyupdateforkeys script.js
require("babel-core").transform("code", {
plugins: ["flow-onlyupdateforkeys"]
});
Note that when using this plugin with flow-runtime, you must ensure that babel-plugin-flow-onlyupdateforkeys is included before babel-plugin-flow-runtime.
.babelrc
{
"plugins": [
"flow-onlyupdateforkeys",
"flow-runtime"
]
}