I believe that the issue is here:
Eggs.data !== 'undefined'
this is comparing to a string 'undefined'.
What you want is Eggs.data !== undefined
or !Eggs.data
or typeof Eggs.data !== 'undefined'
Also, you have some TypeScript issues I believe,
if you do:
setEggs({ data });
Then you should initialize Eggs like this
const [Eggs, setEggs] = useState<{data: EggsPlace[]}>({data: []});
That would also make sure your initialise data with an empty array. Although, it would still break if data
in setEggs({ data });
is not an array.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…