UseEffect doesn’t work in React Native

Share on facebook
Share on google
Share on twitter
Share on linkedin

https://www.reddit.com/r/reactnative/comments/ekcfif/useeffect_doesnt_work_in_react_native/

Hi,

I have installed axios in order to perform a basic get request to an API. To this purpose, I use React's useEffect:

export default function Home() { const [poke, setPoke] = useState([]); useEffect(() => { axios.get("https://pokeapi.co/api/v2/pokemon/pikachu") .then(res => setPoke(res.data)) .catch(err => console.log(err)); }, []); 

The useEffect is called when the component mounts (I've removed all the consol.log for more clarity), but nothing happens afterwards. Nor then nor catch are called. Is there something wrong with my script or is useEffect not allowed in React Native?

Thanks!

submitted by /u/MonsieurLeland
[link] [comments]

Sign up for our Newsletter

Agree to our privacy policy.