skip to Main Content

Why is app fetching on input change in react? – Reactjs

import './App.css'; import Axios from 'axios'; import {useState} from 'react'; function App() { const [name, setName] = useState(''); const fetchData = () => { Axios.get(`https://api.agify.io/?name=${name}`).then((res)=> { console.log(res.data) }) } return ( <div className="App"> <input placeholder='Ex. John' onChange={(e)=> {setName(e.target.value)}}></input> <button onClick={fetchData()}>Predict…

VIEW QUESTION
Back To Top
Search