@@ -2,46 +2,47 @@ import React, { useCallback, useRef, useState } from 'react';
22import config from 'devextreme/core/config' ;
33import repaintFloatingActionButton from 'devextreme/ui/speed_dial_action/repaint_floating_action_button' ;
44import DataGrid , {
5- Column , Editing , Lookup , Texts , Selection , type DataGridTypes ,
5+ Column , Editing , Lookup , Texts , Selection ,
66} from 'devextreme-react/data-grid' ;
77import { SpeedDialAction } from 'devextreme-react/speed-dial-action' ;
8- import { SelectBox , type SelectBoxTypes } from 'devextreme-react/select-box' ;
8+ import { SelectBox } from 'devextreme-react/select-box' ;
9+ import type { SelectBoxTypes } from 'devextreme-react/select-box' ;
10+ import type { DataGridTypes , DataGridRef } from 'devextreme-react/data-grid' ;
911import {
10- employees , states , directions , directionLabel ,
12+ employees , states , directions , optionDirections , directionLabel ,
1113} from './data.ts' ;
12-
13- const optionDirections = [ 'auto' , 'up' , 'down' ] ;
14+ import type { DirectionKey } from './data.ts' ;
1415
1516const App = ( ) => {
1617 const [ selectedRowIndex , setSelectedRowIndex ] = useState ( - 1 ) ;
17- const gridRef = useRef ( null ) ;
18+ const gridRef = useRef < DataGridRef > ( null ) ;
1819
1920 const selectedChanged = useCallback ( ( e : DataGridTypes . SelectionChangedEvent ) => {
2021 setSelectedRowIndex ( e . component . getRowIndexByKey ( e . selectedRowKeys [ 0 ] ) ) ;
21- } , [ setSelectedRowIndex ] ) ;
22+ } , [ ] ) ;
2223
2324 const directionChanged = useCallback ( ( e : SelectBoxTypes . SelectionChangedEvent ) => {
2425 config ( {
25- floatingActionButtonConfig : directions [ e . selectedItem ] ,
26+ floatingActionButtonConfig : directions [ e . selectedItem as DirectionKey ] ,
2627 } ) ;
2728
2829 repaintFloatingActionButton ( ) ;
2930 } , [ ] ) ;
3031
3132 const editRow = useCallback ( ( ) => {
32- gridRef . current . instance ( ) . editRow ( selectedRowIndex ) ;
33- gridRef . current . instance ( ) . deselectAll ( ) ;
34- } , [ gridRef , selectedRowIndex ] ) ;
33+ gridRef . current ? .instance ( ) ? .editRow ( selectedRowIndex ) ;
34+ gridRef . current ? .instance ( ) ? .deselectAll ( ) ;
35+ } , [ selectedRowIndex ] ) ;
3536
3637 const deleteRow = useCallback ( ( ) => {
37- gridRef . current . instance ( ) . deleteRow ( selectedRowIndex ) ;
38- gridRef . current . instance ( ) . deselectAll ( ) ;
39- } , [ gridRef , selectedRowIndex ] ) ;
38+ gridRef . current ? .instance ( ) ? .deleteRow ( selectedRowIndex ) ;
39+ gridRef . current ? .instance ( ) ? .deselectAll ( ) ;
40+ } , [ selectedRowIndex ] ) ;
4041
4142 const addRow = useCallback ( ( ) => {
42- gridRef . current . instance ( ) . addRow ( ) ;
43- gridRef . current . instance ( ) . deselectAll ( ) ;
44- } , [ gridRef ] ) ;
43+ gridRef . current ? .instance ( ) ? .addRow ( ) ;
44+ gridRef . current ? .instance ( ) ? .deselectAll ( ) ;
45+ } , [ ] ) ;
4546
4647 return (
4748 < div >
0 commit comments