import { useState, useEffect, useCallback } from 'react' import './App.css' function App() { const getCategories = (type) => { if(type === 'sfw'){ return ['waifu', 'neko', 'shinobu', 'blush', 'bully', 'cuddle', 'cry', 'cringe', 'dance', 'happy', 'poke', 'wink', 'kick', 'kill', 'slap', 'glomp', 'bite', 'nom', 'handhold', 'highfive', 'wave', 'smile', 'yeet', 'smug', 'pat', 'lick', 'kiss', 'awoo', 'hug', 'megumin']; } else{ return ['waifu', 'neko', 'trap', 'blowjob']; } return []; } const handleType = () => { setType((prev) => (prev === 'sfw' ? 'nsfw' : 'sfw') ); setCategory(getCategories(type)[0]); } const [type, setType] = useState('sfw') const [waifu, setWaifu] = useState('') const [waifu2, setWaifu2] = useState('') const [waifu3, setWaifu3] = useState('') const [categories, setCategories] = useState(getCategories('sfw')) const [category, setCategory] = useState(categories[0]) const [nsfwAllowed, setNsfwAllowed] = useState(false) const apiUrl = `https://api.waifu.pics/${type}/${category}` const fetchImage1 = async() => { const response1 = await fetch(apiUrl) const data1 = await response1.json() if (response1.ok ) { setWaifu(data1.url) } } const fetchImage2 = async() => { const response2 = await fetch(apiUrl) const data2 = await response2.json() if (response2.ok ) { setWaifu2(data2.url) } } const fetchImage3 = async() => { const response3 = await fetch(apiUrl) const data3 = await response3.json() if (response3.ok ) { setWaifu3(data3.url) console.log(data3.url) console.log(data3) console.log(apiUrl) } } useEffect(()=>{ fetchImage1(); fetchImage2(); fetchImage3(); }, [setType, category]) const btnChange = () => { fetchImage1(); fetchImage2(); fetchImage3(); } return ( <>
> ) } export default App