@@ -12,21 +12,20 @@ export interface SelectionAreaProps extends PartialSelectionOptions, React.HTMLA
1212 onStop ?: SelectionEvents [ 'stop' ] ;
1313}
1414
15- const SelectionContext = createContext < VanillaSelectionArea | undefined > ( undefined ) ;
15+ const SelectionContext = createContext < VanillaSelectionArea | undefined > ( undefined ) ;
1616
1717export const useSelection = ( ) => useContext ( SelectionContext ) ;
1818
1919export const SelectionArea : React . FunctionComponent < SelectionAreaProps > = props => {
20- const [ selectionState , setSelection ] = useState < VanillaSelectionArea | undefined > ( undefined ) ;
20+ const [ instance , setInstance ] = useState < VanillaSelectionArea | undefined > ( undefined ) ;
2121 const root = useRef < HTMLDivElement > ( null ) ;
2222
2323 useEffect ( ( ) => {
2424 /* eslint-disable @typescript-eslint/no-unused-vars */
25- const { boundaries, onBeforeStart, onBeforeDrag, onStart, onMove, onStop, ...opt } = props ;
26- const areaBoundaries = boundaries ? boundaries : ( root . current as HTMLElement ) ;
25+ const { boundaries = root . current , onBeforeStart, onBeforeDrag, onStart, onMove, onStop, ...opt } = props ;
2726
2827 const selection = new VanillaSelectionArea ( {
29- boundaries : areaBoundaries ,
28+ boundaries : boundaries as HTMLElement ,
3029 ...opt
3130 } ) ;
3231
@@ -36,16 +35,16 @@ export const SelectionArea: React.FunctionComponent<SelectionAreaProps> = props
3635 selection . on ( 'move' , evt => props . onMove ?.( evt ) ) ;
3736 selection . on ( 'stop' , evt => props . onStop ?.( evt ) ) ;
3837
39- setSelection ( selection ) ;
38+ setInstance ( selection ) ;
4039
4140 return ( ) => {
4241 selection . destroy ( ) ;
43- setSelection ( undefined ) ;
42+ setInstance ( undefined ) ;
4443 } ;
4544 } , [ ] ) ;
4645
4746 return (
48- < SelectionContext . Provider value = { selectionState } >
47+ < SelectionContext . Provider value = { instance } >
4948 { props . boundaries ? (
5049 props . children
5150 ) : (
0 commit comments