facebook / react

The library for web and native user interfaces.
https://react.dev
MIT License
228.52k stars 46.76k forks source link

Unhandled Rejection (SyntaxError): Unexpected token < in JSON at position 0 #12398

Closed ep1982 closed 6 years ago

ep1982 commented 6 years ago

Hello all, I'm new with react. I want import some datas of my file data.json. The code is:

Portfolio.js

import React, { Component } from 'react';

class Portfolio extends Component {
  constructor(){
    super();
    this.state = { websites: [] }
  }
  componentWillMount(){
    fetch('./data.json')
      .then(response => response.json())
      .then(({websites}) => this.setStates({websites}));
   }
  render() {
     let websites = this.state.websites
    return (
      <div className="portfolio" id="portfolio">
        <div className="container v-center align-center">
          <h2>Portfolio</h2>
          <p>My latest portfolio list</p>
          {websites.map(item =>
            <div className="sm-12 md-12 lg-12">
            <h1 key={item.title}>{item.title}</h1>
            <p>{item.description}</p>
          </div>

        )}
        </div>
      </div>
    );
  }
}

export default Portfolio;

data.json

{
  "websites":[
    {
      "title":"Estancia La Vera Cruz",
      "image":"./assets/images/estancia.jpg",
      "description":"The Estancia La Vera Cruz, is a recognized company of international class that offers hotel services. My work with the Estancia team began from 2011, reprogramming his first website made in PHP. I created a template for Joomla 1.5 keeping the original version, I made SEO on page and the google positioning using the words Estancias en Venezuela. In 2014, the website was completely changed by a responsive, flat and minimalist design, I continued using Joomla as CMS with the version 3.5",
      "year":"2011 - 2018",
      "qualities": [
        "qualita 1",
        "qualita 2",
        "qualita 3"
      ]
    }
  ]
}

This is the error

Unhandled Rejection (SyntaxError): Unexpected token < in JSON at position 0
(anonymous function)
src/partial/Portfolio.js:10
   7 | }
   8 | componentWillMount(){
   9 |   fetch('./data.json')
> 10 |     .then(response => response.json())
  11 |     .then(({websites}) => this.setStates({websites}));
  12 |  }
  13 | render() {

Please I need your help

aweary commented 6 years ago

Hey there! We use the issue tracker for bug reports and feature requests.

If you have a question, please check our community support resources: https://facebook.github.io/react/community/support.html