I am working on Reactjs and using nextjs,I am fetching data using axios, I just want to check before map/loop that whether whether array is empty or not , means if code/loop should work if i have data in array (students.data),How can i do this ? Here is my current code
const [students,setStudents] = useState({
data: '',
loading: true
})
const [name,setName] = useState('');
const handleClick2 = async() => {
$("#mostviews").hide();
const response = await axios.get(`https://xxxxxxxxxxxxxx.com/${spath}`)
setStudents({
data: response.data,
loading: false
})
}
{students.data.map((caseStudy ) => (
<a>{caseStudy.title}</a>
))}
In Network tab i am getting data like following way
0 Object { id: "66", cat_name: "pined", title: "Game Engine", … }
1 Object { id: "40", cat_name: "pined", title: "Alpha Release Time !", … }