@@ -103,7 +103,6 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
103
103
104
104
componentDidMount ( ) {
105
105
const {
106
- getContainer,
107
106
useWindowAsScrollContainer,
108
107
} = this . props ;
109
108
@@ -113,27 +112,29 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
113
112
* https://github.com/clauderic/react-sortable-hoc/issues/249
114
113
*/
115
114
116
- this . container = typeof getContainer === 'function'
117
- ? getContainer ( this . getWrappedInstance ( ) )
118
- : findDOMNode ( this ) ;
119
- this . document = this . container . ownerDocument || document ;
120
-
121
- const contentWindow = this . props . contentWindow || this . document . defaultView || window ;
122
-
123
- this . contentWindow = typeof contentWindow === 'function'
124
- ? contentWindow ( )
125
- : contentWindow ;
126
- this . scrollContainer = useWindowAsScrollContainer
127
- ? this . document . scrollingElement || this . document . documentElement
128
- : this . container ;
129
-
130
- for ( const key in this . events ) {
131
- if ( this . events . hasOwnProperty ( key ) ) {
132
- events [ key ] . forEach ( eventName =>
133
- this . container . addEventListener ( eventName , this . events [ key ] , false )
134
- ) ;
115
+ const container = this . getContainer ( ) ;
116
+
117
+ Promise . resolve ( container ) . then ( ( containerNode ) => {
118
+ this . container = containerNode ;
119
+ this . document = this . container . ownerDocument || document ;
120
+
121
+ const contentWindow = this . props . contentWindow || this . document . defaultView || window ;
122
+
123
+ this . contentWindow = typeof contentWindow === 'function'
124
+ ? contentWindow ( )
125
+ : contentWindow ;
126
+ this . scrollContainer = useWindowAsScrollContainer
127
+ ? this . document . scrollingElement || this . document . documentElement
128
+ : this . container ;
129
+
130
+ for ( const key in this . events ) {
131
+ if ( this . events . hasOwnProperty ( key ) ) {
132
+ events [ key ] . forEach ( eventName =>
133
+ this . container . addEventListener ( eventName , this . events [ key ] , false )
134
+ ) ;
135
+ }
135
136
}
136
- }
137
+ } ) ;
137
138
}
138
139
139
140
componentWillUnmount ( ) {
@@ -747,9 +748,20 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
747
748
config . withRef ,
748
749
'To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableContainer() call'
749
750
) ;
751
+
750
752
return this . refs . wrappedInstance ;
751
753
}
752
754
755
+ getContainer ( ) {
756
+ const { getContainer} = this . props ;
757
+
758
+ if ( typeof getContainer !== 'function' ) {
759
+ return findDOMNode ( this ) ;
760
+ }
761
+
762
+ return getContainer ( config . withRef ? this . getWrappedInstance ( ) : undefined ) ;
763
+ }
764
+
753
765
render ( ) {
754
766
const ref = config . withRef ? 'wrappedInstance' : null ;
755
767
0 commit comments