Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

305
Views
TypeError : items.map is not a function

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;
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!