Skip to content

Commit

Permalink
Use typed dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlin committed Oct 12, 2023
1 parent b8c6573 commit 3e77a0a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/components/controls/measurementsOptions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { useDispatch, useSelector } from "react-redux";
import { useSelector } from "react-redux";
import { useAppDispatch } from "../../hooks";
import { isEqual } from "lodash";
import { changeMeasurementsCollection } from "../../actions/measurements";
import {
Expand Down Expand Up @@ -30,7 +31,7 @@ const collectionOptionsSelector = (collections) => {
};

const MeasurementsOptions = () => {
const dispatch = useDispatch();
const dispatch = useAppDispatch();
const collection = useSelector((state) => state.measurements.collectionToDisplay);
const collectionOptions = useSelector((state) => collectionOptionsSelector(state.measurements.collections), isEqual);
const groupBy = useSelector((state) => state.controls.measurementsGroupBy);
Expand Down
5 changes: 3 additions & 2 deletions src/components/controls/panel-toggles.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from "react";
import { useDispatch, useSelector } from "react-redux";
import { useSelector } from "react-redux";
import { useAppDispatch } from "../../hooks";
import { useTranslation } from 'react-i18next';

import Toggle from "./toggle";
import { togglePanelDisplay } from "../../actions/panelDisplay";
import { RootState } from "../../store";

export default function PanelToggles() {
const dispatch = useDispatch();
const dispatch = useAppDispatch();
const { t } = useTranslation();

const panelsAvailable = useSelector((state: RootState) => state.controls.panelsAvailable);
Expand Down
4 changes: 2 additions & 2 deletions src/components/narrativeEditor/examineNarrative.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useRef, useEffect } from "react";
import { useDispatch } from 'react-redux';
import { useAppDispatch } from "../../hooks";
import { getDatasetNamesFromUrl } from "../../actions/loadData";
import { CLEAN_START } from "../../actions/types";
import { createStateFromQueryOrJSONs } from "../../actions/recomputeReduxState";
Expand Down Expand Up @@ -159,7 +159,7 @@ const NarrativeSummary = ({summary, datasetResponses, showNarrative}) => {
};

const ExamineNarrative = ({narrative, datasetResponses, setDisplayNarrative}) => {
const dispatch = useDispatch();
const dispatch = useAppDispatch();
const el = useRef(null);
useEffect(() => {
/* when a narrative is loaded then we want to focus on <ExamineNarrative> however
Expand Down
4 changes: 2 additions & 2 deletions src/components/narrativeEditor/useDatasetFetch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useEffect, useReducer, useRef} from "react";
import { useDispatch } from 'react-redux';
import { useAppDispatch } from "../../hooks";
import { CACHE_JSONS } from "../../actions/types";
import { FetchError } from "../../util/exceptions";

Expand All @@ -14,7 +14,7 @@ import { FetchError } from "../../util/exceptions";
*/

export function useDatasetFetch(datasets) {
const dispatchRedux = useDispatch();
const dispatchRedux = useAppDispatch;

This comment has been minimized.

Copy link
@victorlin

victorlin Nov 16, 2023

Author Member

This was not done properly. Fixed in d1d7814.

const [datasetResponses, dispatchDatasetResponses] = useReducer(
(state, action) => {
if (action.reset) return {};
Expand Down
6 changes: 6 additions & 0 deletions src/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'
import type { RootState, AppDispatch } from './store'


export const useAppDispatch: () => AppDispatch = useDispatch
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector

0 comments on commit 3e77a0a

Please sign in to comment.