From 26225005bea2e6ca7c47012fdf015802ce4e402f Mon Sep 17 00:00:00 2001 From: shams mosowi Date: Tue, 24 Sep 2019 12:15:13 +1000 Subject: [PATCH] change table on path change --- src/components/Table/index.tsx | 6 ++++-- src/hooks/useFiretable/index.ts | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index 06e43f04..1f6e43bb 100644 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import ReactDataGrid from "react-data-grid"; import useFiretable from "../../hooks/useFiretable"; import { createStyles, Theme, makeStyles } from "@material-ui/core/styles"; @@ -36,7 +36,9 @@ const useStyles = makeStyles(Theme => function Table(props: any) { const { collection } = props; const { tableState, tableActions } = useFiretable(collection); - + useEffect(() => { + tableActions.set(collection); + }, [collection]); const classes = useStyles(); const [anchorEl, setAnchorEl] = useState(null); diff --git a/src/hooks/useFiretable/index.ts b/src/hooks/useFiretable/index.ts index 7e0cdcb6..aeceaa9c 100644 --- a/src/hooks/useFiretable/index.ts +++ b/src/hooks/useFiretable/index.ts @@ -12,7 +12,7 @@ export type FiretableActions = { update: Function; }; row: { add: any; delete: Function }; - table: { set: Function }; + set: Function; }; export type FiretableState = { @@ -48,7 +48,7 @@ const useFiretable = (collectionName: string) => { remove: configActions.remove, }, row: { add: tableActions.addRow, delete: tableActions.deleteRow }, - table: { set: setTable }, + set: setTable, }; return { tableState: state, tableActions: actions };