I want to get real time bitcoin information but datas not coming. I get this error = React Hook useEffect has a missing dependency: 'coinData'. Either include it or remove the dependency array
const [coinData,setCoinData] = useState([]);
useEffect(() => {
const getData = async () =>{
const baseURL = "https://api.coingecko.com/api/v3/coins/bitcoin?tickers=true&market_data=true&community_data=true&developer_data=true&sparkline=true"
const response = await axios(baseURL)
setCoinData(response);
console.log(coinData)
}
getData();
}, []);
CodePudding user response:
The error is because you're using coinData
(state) inside useEffect
.
If you add coindData
to the dependencies array, you'll get an infinite loop.
To log the response use console.log(response)
, not console.log(coinData)
.
useEffect(() => {
const getData = async () =>{
const baseURL = "https://api.coingecko.com/api/v3/coins/bitcoin?tickers=true&market_data=true&community_data=true&developer_data=true&sparkline=true"
const response = await axios(baseURL)
setCoinData(response);
console.log(response);
}
getData();
}, []);