Consuming API Reactjs

Asked

Viewed 583 times

0

I’m new to Reactjs, when I try to consume a local API I can’t, I believe that’s the 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>
        )
      }

2 answers

0


Check if the address http://localhost:3010/test 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 kind of 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 its own editor. When I first started using it, I still use it. I’m still learning, there are many interesting concepts, which will help you in programming javascript ES6 and JSX code (which use those pseudo Html markings as and others.

-3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.