From af9acbd31eb124458bc1164956345ef59b15b491 Mon Sep 17 00:00:00 2001 From: lz Date: Wed, 7 Nov 2018 15:51:52 +0800 Subject: [PATCH] Add getWrappedInstance method for LoadableComponent --- src/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 14b5bfa3..206d6d0d 100644 --- a/src/index.js +++ b/src/index.js @@ -229,6 +229,10 @@ function createLoadableComponent(loadFn, options) { this._loadModule(); }; + getWrappedInstance = () => { + return this._wrappedInstance; + }; + render() { if (this.state.loading || this.state.error) { return React.createElement(opts.loading, { @@ -239,7 +243,11 @@ function createLoadableComponent(loadFn, options) { retry: this.retry }); } else if (this.state.loaded) { - return opts.render(this.state.loaded, this.props); + return opts.render(this.state.loaded, Object.assign( + {}, + this.props, + { ref: ref => this._wrappedInstance = ref } + )); } else { return null; }