why my code shows
TypeError : items.map is not a function
I am trying to learn USEEFFECT HOOK in reactjs and i am getting this error for a lot of times. I am severely confused...
import './App.css'
import React, { useState, useEffect } from 'react'
function App() {
const [type, setType] = useState(''),
[items, setItems] = useState('')
useEffect(() => {
fetch(`https://jsonplaceholder.typicode.com/${type}`)
.then(response => response.json())
.then(json => setItems(json))
console.log(items)
}, [type])
return (
<div className="App">
<button onClick={() => setType('posts')}>posts</button>
<button onClick={() => setType('users')}>users</button>
<button onClick={() => setType('comments')}>comments</button>
<div>{type}</div>
{items.map(el => {
return JSON.stringify(el)
})}
</div>
);
}
export default App;