Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
ThieryMichel committed Jul 10, 2019
1 parent 3a983d9 commit 3548e8d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions packages/ra-core/src/controller/usePaginationState.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -10,7 +10,10 @@ interface PaginationProps {
setPagination: (pagination: Pagination) => void;
}

const paginationReducer = (prevState, nextState) => {
const paginationReducer = (
prevState: Pagination,
nextState: Partial<Pagination>
): Pagination => {
return {
...prevState,
...nextState,
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/controller/useSortState.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down

0 comments on commit 3548e8d

Please sign in to comment.