11import * as React from 'react' ;
2- import PropTypes from 'prop-types' ;
32import { findDOMNode } from 'react-dom' ;
43import invariant from 'invariant' ;
54
@@ -37,17 +36,24 @@ import {
3736 defaultKeyCodes ,
3837} from './props' ;
3938
39+ export const SortableContext = React . createContext ( {
40+ manager : { } ,
41+ } ) ;
42+
4043export default function sortableContainer (
4144 WrappedComponent ,
4245 config = { withRef : false } ,
4346) {
4447 return class WithSortableContainer extends React . Component {
4548 constructor ( props ) {
4649 super ( props ) ;
50+ const manager = new Manager ( ) ;
4751
4852 validateProps ( props ) ;
4953
50- this . manager = new Manager ( ) ;
54+ this . manager = manager ;
55+ this . wrappedInstance = React . createRef ( ) ;
56+ this . sortableContextValue = { manager} ;
5157 this . events = {
5258 end : this . handleEnd ,
5359 move : this . handleMove ,
@@ -60,15 +66,6 @@ export default function sortableContainer(
6066 static displayName = provideDisplayName ( 'sortableList' , WrappedComponent ) ;
6167 static defaultProps = defaultProps ;
6268 static propTypes = propTypes ;
63- static childContextTypes = {
64- manager : PropTypes . object . isRequired ,
65- } ;
66-
67- getChildContext ( ) {
68- return {
69- manager : this . manager ,
70- } ;
71- }
7269
7370 componentDidMount ( ) {
7471 const { useWindowAsScrollContainer} = this . props ;
@@ -898,7 +895,7 @@ export default function sortableContainer(
898895 'To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableContainer() call' ,
899896 ) ;
900897
901- return this . refs . wrappedInstance ;
898+ return this . wrappedInstance . current ;
902899 }
903900
904901 getContainer ( ) {
@@ -1047,9 +1044,13 @@ export default function sortableContainer(
10471044 } ;
10481045
10491046 render ( ) {
1050- const ref = config . withRef ? ' wrappedInstance' : null ;
1047+ const ref = config . withRef ? this . wrappedInstance : null ;
10511048
1052- return < WrappedComponent ref = { ref } { ...omit ( this . props , omittedProps ) } /> ;
1049+ return (
1050+ < SortableContext . Provider value = { this . sortableContextValue } >
1051+ < WrappedComponent ref = { ref } { ...omit ( this . props , omittedProps ) } />
1052+ </ SortableContext . Provider >
1053+ ) ;
10531054 }
10541055
10551056 get helperContainer ( ) {
0 commit comments