How to fix ‘items.map is not define’ error in Reactjs

how to fix anything
how to fix phone
how to fix a zipper
ifixit
how to fix a computer
how to fix broken things
how to fix stuff
how to fix keyboard

I'm just new developer about reactjs

I'm try to map data.I am following reactjs tutorial and this is my result, but i trying and trying again is it not working. How can i solve is ??

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      error: null,
      isLoaded: false,
      items: []
    };
  }
  componentDidMount() {
 // API from reqres
    fetch("https://reqres.in/api/users/2")
      .then(res => res.json())
      .then(
        (result) => {
          console.log(result.data);
          this.setState({
            isLoaded: true,
            items: result.data
          });
        },
        (error) => {
          this.setState({
            isLoaded: true,
            error
          });
        }
      )
  }
  render() {
    const { error, isLoaded, items } = this.state;
    if (error) {
      return <div>Error: {error.message}</div>;
    } else if (!isLoaded) {
      return <div>Loading...</div>;
    } else {
      return (
        <div>
//this is the problem
          {items.map(item=> { 
            return <div>
              <p>{item.id}</p>
            </div>
          })}
        </div>
      );
    }
  }
}

export default App;

Please help me, I just want to view my data :(

After I change fetch to Axios i have the same problem ??

    Axios({
      method:"GET",
      url:"https://reqres.in/api/users"
    }).then(res => {
      this.setState({
         isLoaded:true,
           items: res.data
      })
      console.log(res.data)

  }).catch(err => {
      console.log(err)

  })

Fetch data from "https://reqres.in/api/users" and use that data, becouse /users returns array of users,and /users/2 returns user object for userId=2.

How To Repair Almost Everything, Timestamps 00:01 Slime cleaning trick 02:29 Coca-cola rust removal 02:55 Wall repair trick 03 Duration: 13:56 Posted: 21 Apr 2020 iFixit is a global community of people helping each other repair things. Let's fix the world, one device at a time. Troubleshoot with experts in the Answers forum—and build your own how-to guides to share with the world. Fix your Apple and Android devices—and buy all the parts and tools needed for your DIY repair projects.

You can fix this by giving items a default value:

const { error, isLoaded, items = [] } = this.state;

Repair Manuals for Every Thing, iFixit is a global community of people helping each other repair things. Let's fix the world, one device at a time. Troubleshoot with experts in the Answers� People Helping People Fix Stuff. Help is here! Learn how to do your own repairs and save money! This site is filled with articles written by skilled individuals. You will find step by step "How To", tips and tricks, and general guidance on fixing your stuff. Finding Solutions

https://reqres.in/api/users/2

This is the response data from server

{
  "data": {
    "id": 2,
    "first_name": "Janet",
    "last_name": "Weaver",
    "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg"
  }
}

If you can change the server, change data result to array. It's gonna works well.

{
  "data": [{
    "id": 2,
    "first_name": "Janet",
    "last_name": "Weaver",
    "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg"
  }]
}

But you can't change the response data, you can't use with .map

render() {
    const { error, isLoaded, items } = this.state;
    if (error) {
      return <div>Error: {error.message}</div>;
    } else if (!isLoaded) {
      return <div>Loading...</div>;
    } else {
      return (
        <div>
//just use for one(object)
            <div>
              <p>{item.id}</p>
            </div>
        </div>
      );
    }
  }

iFixit: The Free Repair Manual, Bad back, blotchy skin, and a wobbly feeling in your gut? Our anatomies are feeling the strain of too long spent at home. Here's how: 1. Navigate to the Windows 10 Advanced Startup Options menu. On many laptops, hitting F11 as soon as you power on will 2. Click Startup Repair.

What lockdown has done to our bodies – and how to fix it, What will be the lasting effects of technology, social media and lockdown on the minds of young people? How to Fix the Most Annoying Things in Windows 10. Windows 10 is great, but it has its issues, from unpredictable reboots to Cortana. Here's how to fix some of the more irritating quirks with

The future of Gen Z's mental health: How to fix the 'unhappiest , Click on the category image of the appliance that you have a problem with. Find your Repair guide. Make shore your watch the right tutorial. Then find the spare� Here are 6 steps to fix it yourself. Don't get frustrated and give up on a slow PC, take a few minutes to troubleshoot and remedy it. Jason Cipriani. May 7, 2020 3:00 a.m. PT.

How to Repair, Buy How to Fix (Just About) Everything: More Than 550 Step-By-Step Instructions for Everything from Fixing a Faucet to Removing Mystery Stains to Curing a by�

Comments
  • Can you log what items is within the render function and tell us the result?
  • Return data from reqres.in/api/users/2 is not array. data is object. The map method is for Array.
  • thank kkangil, but what is for my api ??
  • I see my problem then, tks ivica.moke a lot :))
  • Glad I could help :)