How to do default sorting in react-table

hotbreakb·2023년 5월 31일
0

react-table에서 useTable이나 <Table />을 사용할 때 초기 sorting을 적용하려면 useSortBy를 사용하면 된다.

const { getTableProps, getTableBodyProps, headerGroups, prepareRow, rows } =
    useTable(
      {
        columns,
        data,
        initialState: {
          ...,
          sortBy: [
            {
              id: "sortedBy",
              desc: true,
            },
          ],
        },
      },
      useSortBy
    );

참고 자료

profile
글쟁이 프론트 개발자, 헬렌입니다.

0개의 댓글