Skip to content

Commit aa7a3b6

Browse files
anaisbergSimonClo
authored andcommitted
♻️ add hooks
1 parent 823d8f0 commit aa7a3b6

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/DatabaseBlock/DatabaseGrid.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ColDef, ColSpanParams, ICellRendererParams } from 'ag-grid-community';
22
import { AgGridReact } from 'ag-grid-react';
3-
import { useEffect, useRef, useState } from 'react';
3+
import { useEffect, useRef } from 'react';
44

55
import { Box } from '@/components';
66
import {
@@ -11,6 +11,7 @@ import {
1111

1212
import { AddButtonComponent } from './AddColumnButton';
1313
import { AddRowButton } from './AddRowButton';
14+
import { useColumns, useRows } from './hooks';
1415
import { createNewRow } from './utils';
1516

1617
export const DatabaseGrid = ({
@@ -29,9 +30,8 @@ export const DatabaseGrid = ({
2930

3031
const { createColumns } = useGristCrudColumns();
3132

32-
const [rowData, setRowData] =
33-
useState<Record<string, string | number | boolean>[]>();
34-
const [colDefs, setColDefs] = useState<ColDef[]>();
33+
const { rowData, setRowData } = useRows();
34+
const { colDefs, setColDefs } = useColumns();
3535

3636
const newRowColSpan = (params: ColSpanParams<Record<string, string>>) => {
3737
const colsValues = params.data ?? {};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ColDef } from 'ag-grid-community';
2+
import { useState } from 'react';
3+
4+
export const useColumns = () => {
5+
const [colDefs, setColDefs] = useState<ColDef[]>();
6+
7+
return { colDefs, setColDefs };
8+
};
9+
10+
export const useRows = () => {
11+
const [rowData, setRowData] =
12+
useState<Record<string, string | number | boolean>[]>();
13+
14+
return { rowData, setRowData };
15+
};

0 commit comments

Comments
 (0)