1
1
import * as React from 'react' ;
2
- import PropTypes from 'prop-types' ;
3
2
import { findDOMNode } from 'react-dom' ;
4
3
import invariant from 'invariant' ;
5
4
@@ -37,17 +36,24 @@ import {
37
36
defaultKeyCodes ,
38
37
} from './props' ;
39
38
39
+ export const SortableContext = React . createContext ( {
40
+ manager : { } ,
41
+ } ) ;
42
+
40
43
export default function sortableContainer (
41
44
WrappedComponent ,
42
45
config = { withRef : false } ,
43
46
) {
44
47
return class WithSortableContainer extends React . Component {
45
48
constructor ( props ) {
46
49
super ( props ) ;
50
+ const manager = new Manager ( ) ;
47
51
48
52
validateProps ( props ) ;
49
53
50
- this . manager = new Manager ( ) ;
54
+ this . manager = manager ;
55
+ this . wrappedInstance = React . createRef ( ) ;
56
+ this . sortableContextValue = { manager} ;
51
57
this . events = {
52
58
end : this . handleEnd ,
53
59
move : this . handleMove ,
@@ -60,15 +66,6 @@ export default function sortableContainer(
60
66
static displayName = provideDisplayName ( 'sortableList' , WrappedComponent ) ;
61
67
static defaultProps = defaultProps ;
62
68
static propTypes = propTypes ;
63
- static childContextTypes = {
64
- manager : PropTypes . object . isRequired ,
65
- } ;
66
-
67
- getChildContext ( ) {
68
- return {
69
- manager : this . manager ,
70
- } ;
71
- }
72
69
73
70
componentDidMount ( ) {
74
71
const { useWindowAsScrollContainer} = this . props ;
@@ -898,7 +895,7 @@ export default function sortableContainer(
898
895
'To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableContainer() call' ,
899
896
) ;
900
897
901
- return this . refs . wrappedInstance ;
898
+ return this . wrappedInstance . current ;
902
899
}
903
900
904
901
getContainer ( ) {
@@ -1047,9 +1044,13 @@ export default function sortableContainer(
1047
1044
} ;
1048
1045
1049
1046
render ( ) {
1050
- const ref = config . withRef ? ' wrappedInstance' : null ;
1047
+ const ref = config . withRef ? this . wrappedInstance : null ;
1051
1048
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
+ ) ;
1053
1054
}
1054
1055
1055
1056
get helperContainer ( ) {
0 commit comments