import { useContext } from "react"; import { ProfileContext } from "../App"; import { useQuery } from '@tanstack/react-query'; import axios from 'axios'; const Home = () => { const { username } = useContext(ProfileContext); const { data: catData, isError, error, refetch, isFetching } = useQuery({ queryKey: ["cat key"], enabled: false, queryFn: async () => { return axios.get("https://catfact.ninja/fact").then(res => res.data); } }); if (isFetching) { return

Loading...

; } if (isError) { return
Error fetching cat fact! {error.message}
; } // --- رندر نهایی --- return (

Home page - Username is: {username}

{/* اگر داده‌ای نداریم (حالت اولیه) */} {!catData ? ( ) : ( // اگر داده داریم (حالت موفقیت) <>

Cat Fact :

{catData?.fact}

)}
); } export default Home;