bugfix: remove infinite renderloop of onSortUpdate
This commit is contained in:
@ -3,7 +3,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|||||||
import DropdownButton from './DropdownButton';
|
import DropdownButton from './DropdownButton';
|
||||||
import { IconProp } from '@fortawesome/fontawesome-svg-core';
|
import { IconProp } from '@fortawesome/fontawesome-svg-core';
|
||||||
import SortAndFilterBar, { SortType } from './SortAndFilterBar';
|
import SortAndFilterBar, { SortType } from './SortAndFilterBar';
|
||||||
import { useEffect, useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
viewName: string;
|
viewName: string;
|
||||||
@ -53,21 +53,22 @@ function TableHeader({
|
|||||||
const [sorts, setSorts] = useState([] as Array<SortType>);
|
const [sorts, setSorts] = useState([] as Array<SortType>);
|
||||||
|
|
||||||
const onSortItemSelect = (sortId: string) => {
|
const onSortItemSelect = (sortId: string) => {
|
||||||
setSorts([
|
const newSorts = [
|
||||||
{
|
{
|
||||||
label: 'Created at',
|
label: 'Created at',
|
||||||
order: 'asc',
|
order: 'asc',
|
||||||
id: sortId,
|
id: sortId,
|
||||||
} as SortType,
|
} as SortType,
|
||||||
]);
|
];
|
||||||
};
|
setSorts(newSorts);
|
||||||
const onSortItemUnSelect = (sortId: string) => {
|
onSortsUpdate && onSortsUpdate(newSorts);
|
||||||
setSorts([]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
const onSortItemUnSelect = (sortId: string) => {
|
||||||
onSortsUpdate && onSortsUpdate(sorts);
|
const newSorts = [] as SortType[];
|
||||||
}, [sorts, onSortsUpdate]);
|
setSorts(newSorts);
|
||||||
|
onSortsUpdate && onSortsUpdate(newSorts);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledContainer>
|
<StyledContainer>
|
||||||
|
|||||||
Reference in New Issue
Block a user