Skip to content

Commit

Permalink
ui: extract useTypedSlector into a hooks specific file
Browse files Browse the repository at this point in the history
  • Loading branch information
JBWatenbergScality committed Dec 29, 2020
1 parent 4cf9cbd commit 735be21
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ui/src/containers/VolumePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { Breadcrumb } from '@scality/core-ui';
import { PageContainer } from '../components/CommonLayoutStyle';
import { intl } from '../translations/IntlGlobalProvider';
import { useQuery } from '../services/utils';
import { useTypedSelector } from '../ducks/reducer';
import { useTypedSelector } from '../hooks';

// <VolumePage> component fetchs all the data used by volume page from redux store.
// the data for <VolumeMetricGraphCard>: get the default metrics time span `last 24 hours`, and the component itself can change the time span base on the dropdown selection.
Expand Down
6 changes: 0 additions & 6 deletions ui/src/ducks/reducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@flow
import { combineReducers } from 'redux';
import { reducer as oidcReducer, UserState } from 'redux-oidc';
import { useSelector } from 'react-redux';

import config from './config';
import type {ConfigState} from './config'
Expand Down Expand Up @@ -55,9 +54,4 @@ export type RootState = {
}
}

export const useTypedSelector: <TSelected>(
selector: (state: RootState) => TSelected,
equalityFn?: (left: TSelected, right: TSelected) => boolean
) => TSelected = useSelector;

export default rootReducer;
12 changes: 12 additions & 0 deletions ui/src/hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@flow
import { useSelector } from 'react-redux';
import type { RootState } from './ducks/reducer';

/**
* It brings automatic strong typing to native useSelector by anotating state with RootState.
* It should be used instead of useSelector to benefit from RootState typing
*/
export const useTypedSelector: <TSelected>(
selector: (state: RootState) => TSelected,
equalityFn?: (left: TSelected, right: TSelected) => boolean
) => TSelected = useSelector;

0 comments on commit 735be21

Please sign in to comment.