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

212
Views
Estoy obteniendo datos dinámicos de mi nodejs para reaccionar, pero aparece un error que dice "POST IS NOT DEFINED"

Hice entradas en mi base de datos mongodb usando el nodo ahora estoy tratando de obtener esos datos del backend para reaccionar en el front-end la aplicación de terceros utilizada para multiplataforma en el nodo son cors y para reaccionar es axios (en el script que he agregado "proxy":"http://localhost:5000"(5000 es mi puerto backend)

Aquí está mi código para NovelCard.js

 import React, { Component } from 'react'; import { Container } from 'react-bootstrap'; import Card from 'react-bootstrap/Card'; import axios from 'axios'; const createSet = (post) => { <Card style={{ width: '18rem' }}> <Card.Img variant="top" src="holder.js/100px180" /> <Card.Body> <Card.Title>{post.name}</Card.Title> <Card.Subtitle className="mb-2 text-muted">{post.author}</Card.Subtitle> <Card.Text>{post.synopsis}</Card.Text> </Card.Body> </Card>; }; class Latest extends Component { state = { name: '', author: '', synopsis: '', post: [], }; componentDidMount = () => { this.getData(); }; getData = () => { axios .get('http://localhost:5000/novels/') .then((res) => { const data = res.data; this.setState({ post: data }); console.log('data recived'); }) .catch(() => { alert('error'); }); }; render() { console.log('state', this.state); return <Container>{post.map(createSet)}</Container>; } } export default Latest;

Recibo un error que dice ***

src\components\home\Latest\NovelCard.js Línea 45:24: 'post' no está definido no-undef


over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Su variable post está disponible dentro de su estado. Debe hacer algo como esto dentro de su función de render .

 render() { console.log('state', this.state); return <Container>{this.state.post.map(createSet)}</Container>; }

O puedes hacer así también.

 render() { const { post } = this.state; console.log('state', this.state); return <Container>{post.map(createSet)}</Container>; }
over 4 years ago · Santiago Trujillo Report
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!