Remove calling async thunk from Filter component using dispatch, but call it directly in slice
parent
3faf494bd0
commit
4cfc08448b
|
@ -1,6 +1,5 @@
|
||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { useAppDispatch, useAppSelector } from 'app/hooks';
|
import { useAppDispatch, useAppSelector } from 'app/hooks';
|
||||||
import { fetchPokemonsInTheRegion } from 'features/Pokedex/pokedexSlice';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
setSelectedRegion,
|
setSelectedRegion,
|
||||||
|
@ -56,7 +55,6 @@ const Filters = () => {
|
||||||
name="regionSelect"
|
name="regionSelect"
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
dispatch(setSelectedRegion(e.target.value));
|
dispatch(setSelectedRegion(e.target.value));
|
||||||
dispatch(fetchPokemonsInTheRegion(e.target.value));
|
|
||||||
}}
|
}}
|
||||||
value={selectedRegion}
|
value={selectedRegion}
|
||||||
>
|
>
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
import { FilterState } from './types/slice';
|
import { FilterState } from './types/slice';
|
||||||
import { RegionPokemonRange } from './types/slice';
|
import { RegionPokemonRange } from './types/slice';
|
||||||
import { pokeApi } from 'app/services/pokeApi';
|
import { pokeApi } from 'app/services/pokeApi';
|
||||||
|
import { fetchPokemonsInTheRegion } from 'features/Pokedex/pokedexSlice';
|
||||||
|
|
||||||
pokeApi.endpoints.getTypeList.initiate(); // initialize type list fetching
|
pokeApi.endpoints.getTypeList.initiate(); // initialize type list fetching
|
||||||
|
|
||||||
|
@ -53,6 +54,7 @@ export const filterSlice: Slice<FilterState> = createSlice({
|
||||||
reducers: {
|
reducers: {
|
||||||
setSelectedRegion: (state, action: PayloadAction<string>) => {
|
setSelectedRegion: (state, action: PayloadAction<string>) => {
|
||||||
state.selectedRegion = action.payload;
|
state.selectedRegion = action.payload;
|
||||||
|
fetchPokemonsInTheRegion(state.selectedRegion);
|
||||||
},
|
},
|
||||||
setSelectedType: (state, action: PayloadAction<string>) => {
|
setSelectedType: (state, action: PayloadAction<string>) => {
|
||||||
state.selectedType = action.payload;
|
state.selectedType = action.payload;
|
||||||
|
|
Loading…
Reference in New Issue