From 3548e8da2d10117dc00eb3f747ffe1a7342fb049 Mon Sep 17 00:00:00 2001 From: thiery Date: Wed, 10 Jul 2019 15:23:04 +0200 Subject: [PATCH] code review --- packages/ra-core/src/controller/usePaginationState.ts | 11 +++++++---- packages/ra-core/src/controller/useSortState.spec.ts | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/ra-core/src/controller/usePaginationState.ts b/packages/ra-core/src/controller/usePaginationState.ts index e3a42735f53..da6e7c0f646 100644 --- a/packages/ra-core/src/controller/usePaginationState.ts +++ b/packages/ra-core/src/controller/usePaginationState.ts @@ -1,4 +1,4 @@ -import { useState, useEffect, useReducer, useMemo, useRef } from 'react'; +import { useState, useEffect, useReducer, useCallback, useRef } from 'react'; import { Pagination } from '../types'; interface PaginationProps { @@ -10,7 +10,10 @@ interface PaginationProps { setPagination: (pagination: Pagination) => void; } -const paginationReducer = (prevState, nextState) => { +const paginationReducer = ( + prevState: Pagination, + nextState: Partial +): Pagination => { return { ...prevState, ...nextState, @@ -56,8 +59,8 @@ export default ( }); const isFirstRender = useRef(true); - const setPerPage = useMemo(() => perPage => setPagination({ perPage }), []); - const setPage = useMemo(() => page => setPagination({ page }), []); + const setPerPage = useCallback(perPage => setPagination({ perPage }), []); + const setPage = useCallback(page => setPagination({ page }), []); useEffect(() => { if (isFirstRender.current) { diff --git a/packages/ra-core/src/controller/useSortState.spec.ts b/packages/ra-core/src/controller/useSortState.spec.ts index fd7ef836375..615e932912b 100644 --- a/packages/ra-core/src/controller/useSortState.spec.ts +++ b/packages/ra-core/src/controller/useSortState.spec.ts @@ -34,7 +34,7 @@ describe('useSortState', () => { }); }); - describe('should provide setSortField method that', () => { + describe('setSortField in return value', () => { it('should just change the order if receiving the current field', () => { const { hookValue, childrenMock } = renderHook(() => useSortState({ field: 'id', order: 'DESC' })