feature: keep callbacks between two renders
This commit is contained in:
@ -4,7 +4,7 @@ import Table from '../../components/table/Table';
|
||||
import styled from '@emotion/styled';
|
||||
import { peopleColumns } from './people-table';
|
||||
import { GraphqlPerson, mapPerson } from '../../interfaces/person.interface';
|
||||
import { useState } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { SortType } from '../../components/table/table-header/SortAndFilterBar';
|
||||
import { OrderBy, usePeopleQuery } from '../../services/people';
|
||||
|
||||
@ -31,10 +31,10 @@ function People() {
|
||||
const [, setSorts] = useState([] as Array<SortType>);
|
||||
const [orderBy, setOrderBy] = useState(defaultOrderBy);
|
||||
|
||||
const updateSorts = (sorts: Array<SortType>) => {
|
||||
const updateSorts = useCallback((sorts: Array<SortType>) => {
|
||||
setSorts(sorts);
|
||||
setOrderBy(sorts.length ? reduceSortsToOrderBy(sorts) : defaultOrderBy);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const { data } = usePeopleQuery(orderBy);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user