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

205
Views
I'm fetching dynamic data from my nodejs to reactjs but I get an error saying "POST IS NOT DEFINED"

I have made entries in my mongodb database using node now I'm trying to fetch that data from backend to react front-end the 3rd party app used for cross-platform in node are cors and for react is axios(in script I have added "proxy":"http://localhost:5000"(5000 is my backend port)

Here is my code for 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;

I'm getting error saying ***

src\components\home\Latest\NovelCard.js Line 45:24: 'post' is not defined no-undef


over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Your post variable is available within you state. You need to do something like this within your render function.

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

Or you can do like this as well.

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!