diff --git a/src/compose.js b/src/compose.js index 8cce3fa..ef79ba1 100644 --- a/src/compose.js +++ b/src/compose.js @@ -14,6 +14,7 @@ export default function compose(dataLoader, options = {}) { propsToWatch = null, // Watch all the props. shouldSubscribe = null, shouldUpdate = null, + withRef = false, } = options; class Container extends React.Component { @@ -119,12 +120,16 @@ export default function compose(dataLoader, options = {}) { ...data, }; - const setChildRef = (c) => { - this.child = c; - }; + const refs = {}; + if (withRef) { + const setChildRef = (c) => { + this.child = c; + }; + refs.ref = setChildRef; + } return ( - + ); } } diff --git a/src/tests/compose.js b/src/tests/compose.js index d2e9aa0..ec3abdd 100644 --- a/src/tests/compose.js +++ b/src/tests/compose.js @@ -72,9 +72,10 @@ describe('compose', () => { }); it('should set the child ref', () => { + const options = { withRef: true }; const Container = compose((props, onData) => { onData(null, { name: 'arunoda' }); - })(Comp); + }, options)(Comp); const el = mount(); expect(el.instance().child.props.name).to.be.equal('arunoda'); });