diff --git a/src/index.js b/src/index.js index c4c6bd3..3ce8816 100644 --- a/src/index.js +++ b/src/index.js @@ -19,21 +19,16 @@ const initMeta = { class Field { static create(com, options = {}) { - return new Field(com, options); + return new this(com, options); } static getUseField({ useState, useMemo }) { - return function(options = {}) { + return (options = {}) => { const [, setState] = useState(); - const field = useMemo(() => { - return new Field( - { - setState, - }, - options - ); - }, [setState]); + const field = useMemo(() => this.create({ setState }, options), [ + setState, + ]); return field; }; diff --git a/test/index.spec.js b/test/index.spec.js index 868a7e9..e7808d6 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -14,12 +14,28 @@ const FormItem = Form.Item; /* eslint-disable react/jsx-filename-extension */ /*global describe it afterEach */ describe('field', () => { - it('should create new field with `Field.create`', function() { - const field = Field.create(this); + describe('Field.create', function() { + it('should create new field', function() { + const field = Field.create(this); + + assert(!!field); + assert(Field.prototype.isPrototypeOf(field)); + }) + + it('should have subclass prototype', function() { + class myField extends Field { + constructor(com, options = {}) { + super(com, options); + } + } + const field = myField.create(this); + + assert(!!field); + assert(myField.prototype.isPrototypeOf(field)); + }) - assert(!!field); - assert(Field.prototype.isPrototypeOf(field)); }) + describe('render', () => { it('should support Form', function(done) { class Demo extends React.Component {