0
0

How to show React API Data

Posted at

import { useEffect, useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'

function App() {
const [user, setUser] = useState([])
const [ageValue,setAgeValue] =useState('')
const url = 'https://dummyjson.com/products';
// const url = 'https://dummyapi.online/api/movies';

const updateAgeValue = (e) => {
console.log(e.target.value)
setAgeValue(e.target.value)
}

async function fetchApi(url) {
const res = await fetch(url)
const data = await res.json();
console.log(data.products)
setUser(data.products)
// console.log(user,"user")
}

useEffect(() => {
fetchApi(url)
}, [])

if (ageValue < 20) {
return (
<>

Hello frind



>
)
} else {
return (
<>

Hello Vite Project



{
user.map((item) =>
<>


{item.id}


{item.brand}


{item.returnPolicy}




{item.rating}


React API Data With Condition


>
)
}
>
)
}
}

export default App

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0