I am use Redux toolkit for show data of a API and I need show for the user a "loading data..." or a spinner before of show the city information.
I am trying use the React Suspense, but don't work. Probably I am doing things wrong.
informationCIty.js (Code with Suspense)
import React, { useEffect, Suspense } from "react";
import { useDispatch, useSelector } from "react-redux";
import { getInformationCity } from "../informationCity/informationCitySlice";
export const InformationCity = () => {
const dispatch = useDispatch();
const selectedCity = useSelector((state) => state?.cities?.selectedCity);
const informacoes = useSelector(
(state) => state?.informationCity?.dataInformation
);
useEffect(() => {
dispatch(getInformationCity(selectedCity));
}, [dispatch, selectedCity]);
return (
<div>
<Suspense fallback="Loading information of city">
{informacoes.map((item, i) => (
<li key={i}>
City ID: {item.id}
<br />
City Name: {item.nome}
<br />
</li>
))}
</Suspense>
</div>
);
};
Someone help me please?