Modify Filter so it send selectedRegion and selectedType to pokedexSlice

This commit is contained in:
Jason Zhu 2023-03-27 23:49:12 +11:00
parent 0b2de88f4a
commit 5c87c25620

View File

@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import {
useGetRegionListQuery,
useGetTypeListQuery,
@ -43,6 +43,20 @@ const Filters = () => {
} = useGetTypeListQuery();
const { data: sortOptions } = useGetSortOptions();
// Send the first region as the default selected region
useEffect(() => {
if (regionsData && regionsData.results.length > 0) {
dispatch(setSelectedRegion(regionsData.results[0].name));
}
}, [regionsData, dispatch]);
// Send the first type as the default selected type
useEffect(() => {
if (typesData && typesData.results.length > 0) {
dispatch(setSelectedType(typesData.results[0].name));
}
}, [typesData, dispatch]);
return (
<>
<div className="filter__container">