Skip to content

Commit

Permalink
fix(ui): cache data list for flags and segments (#3690)
Browse files Browse the repository at this point in the history
Somehow useMemo was missed for those places and if the error occurs
react goes crazy with rerender the page as it gets new empty array
  • Loading branch information
erka authored Dec 6, 2024
1 parent 611382a commit bd51023
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ui/src/components/flags/FlagTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Row,
useReactTable
} from '@tanstack/react-table';
import { useState, useEffect } from 'react';
import { useState, useEffect, useMemo } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { useNavigate } from 'react-router-dom';
import { DataTablePagination } from '~/components/ui/table-pagination';
Expand Down Expand Up @@ -138,7 +138,7 @@ export default function FlagTable(props: FlagTableProps) {
const sorting = useSelector(selectSorting);

const { data, isLoading, error } = useListFlagsQuery(namespace.key);
const flags = data?.flags || [];
const flags = useMemo(() => data?.flags || [], [data]);

const { setError } = useError();
useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/segments/SegmentTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Row,
useReactTable
} from '@tanstack/react-table';
import { useState, useEffect } from 'react';
import { useState, useEffect, useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { selectSorting, setSorting } from '~/app/segments/segmentsApi';
import { useTimezone } from '~/data/hooks/timezone';
Expand Down Expand Up @@ -130,7 +130,7 @@ export default function SegmentTable(props: SegmentTableProps) {

const sorting = useSelector(selectSorting);
const { data, isLoading, error } = useListSegmentsQuery(namespace.key);
const segments = data?.segments || [];
const segments = useMemo(() => data?.segments || [], [data]);
const table = useReactTable({
data: segments,
columns,
Expand Down

0 comments on commit bd51023

Please sign in to comment.