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

218
Views
Map array is not being recognized, so page isn't building

I'm making a bookCatalog for my wife with reactjs, and on landing page I want to show all the books registered. So my code is like shown below, but I'm getting a TypeError: Cannot read properties of undefined (reading 'map') and I don't know what to do.

The actual books array with all the properties saved on mongodb are shown in browser's console, but the page is not building.

import React, { useState, useEffect } from 'react'
import { Link, useHistory } from 'react-router-dom'
import { FiEdit, FiTrash2 } from 'react-icons/fi'
import './styles.css'
import logoImage from '../../assets/logo.svg'
import api from '../../services/api'

export default function BookCatalog() {

  const [bookRepository, setBookRepository] = useState([])

  const history = useHistory()

  useEffect(() => {
    api.get('/books').then(response => {
      setBookRepository(response.data.list)
    })
  })

  return (
    <div className="bookCatalog-container">
      <header>
        <img src={logoImage} alt="Catálogo de livros" />
        <span>Catálogo de Livros</span>
        <Link className="button" to="/NewBook">Adicionar novo livro</Link>
      </header>

      <h1>Livros Registrados</h1>
      <ul>
        {bookRepository.map(book => (
          <li>
            <strong>Título:</strong>
            <p>{book.title}</p>
            <strong>Autor:</strong>
            <p>{book.author}</p>
            <strong>Editora:</strong>
            <p>{book.publishingCompany}</p>
            <strong>Ano de Publicação:</strong>
            <p>{book.publicationYear}</p>
            <strong>Edição:</strong>
            <p>{book.edition}</p>
            <button type="button">
              <FiEdit size={20} color="#251FC5" />
            </button>
            <button type="button">
              <FiTrash2 size={20} color="#251FC5" />
            </button>
          </li>
        ))}
      </ul>
    </div>
  )
}```
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!