Skip to content

Commit c925228

Browse files
tquetano-netflixoliviertassinari
authored andcommitted
Add support for custom createReactClass function name (#177)
* add ability to specify custom name for createReactClass implementation * make test more robust * update README
1 parent 09bf581 commit c925228

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,22 @@ You would use:
225225
classNameMatchers: ["BaseComponent"]
226226
```
227227

228+
### `createReactClassName`
229+
230+
Use this option to set a custom name for the import of the `create-react-class` package that is different than `createReactClass`.
231+
232+
Given this example:
233+
234+
```js
235+
import createClass from 'create-react-class';
236+
```
237+
238+
You would use:
239+
240+
```js
241+
createReactClassName: 'createClass'
242+
```
243+
228244
## Is it safe?
229245

230246
If you are using the `propTypes` in a conventional way,

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export default function(api) {
175175
removeImport: state.opts.removeImport || false,
176176
libraries: (state.opts.additionalLibraries || []).concat('prop-types'),
177177
classNameMatchers,
178+
createReactClassName: state.opts.createReactClassName || 'createReactClass',
178179
}
179180

180181
if (state.opts.plugins) {
@@ -222,7 +223,7 @@ export default function(api) {
222223
}
223224

224225
return (
225-
currentNode.get('callee').node.name === 'createReactClass' ||
226+
currentNode.get('callee').node.name === globalOptions.createReactClassName ||
226227
currentNode.get('callee').node.property.name === 'createClass'
227228
)
228229
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var createSomethingReallySpecial = require('create-react-class');
2+
var PropTypes = require('prop-types');
3+
4+
createSomethingReallySpecial({
5+
propTypes: {
6+
foo: PropTypes.string,
7+
},
8+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var createSomethingReallySpecial = require('create-react-class');
2+
3+
createSomethingReallySpecial({});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"createReactClassName": "createSomethingReallySpecial"
3+
}

0 commit comments

Comments
 (0)