0

I am working with Reactjs,I am using Nextjs,Right now i am using component where i am getting/fetch data using "axios",Problem is whenever i am get empty records( zero record in database) then i am getting following error "this.state.trending.map is not a function" Here is my current component code

import Link from "next/link";
import Moment from 'moment';
class Pin extends React.Component {
    state = {
        trending: []
      }

    componentDidMount() {
        axios.get('http://diggdevelopment.com/blackstallion_new/api/pin',
        )
          .then(res => {
            const trending = res.data;
            this.setState({ trending });
          })
      }

    render() {

      return (
                <>
                   {this.state.trending.map((post, index) => {
                            //...further code...
                   }
            )
amit
  • 1
  • 1
  • 18
  • 28

0 Answers0