Consuming API ReactJs

0

I'm new to ReactJs, when I try to consume a local API I can not, I think it's this message:

  

localhost You need to enable JavaScript to run this app.

My code:

 export default class App extends React.Component {
      state = {
        api: []
      }

      componentDidMount() {
        axios.get('http://localhost:3010/teste')
          .then(res => {
            const api = res.data;
            this.setState({ api  });
          })
      }

      render() {
        return (
          <ul>
            { this.state.api.map(apiaux => 
            <div> 
            <li>{apiaux.id}</li>
            </div>
            )}
          </ul>
        )
      }
    
asked by anonymous 20.08.2018 / 14:22

1 answer

0

Verify that the link address is working normally in the browser (whether it returns data or not). But I believe something is missing in your React environment. If the javascript plugin is enabled in your browser, w if you used boilerplate (which is an initial structure), make sure it is configured correctly. My suggestion is that you use the app generator Which is more or less like this

npx create-react-app my-app cd my-app npm start

Another alternative is to use Rekit Studio. It already comes with the main libraries and even with a publisher of its own. When I started I used it, and I still use it. I'm still learning, have many interesting concepts, which will help you in programming ES6 javascript and JSX code (which use those pseudo Html tags like and others.

    
13.01.2019 / 19:28