So here's the code, I simply want to use axios to get, then set that response to the state. Using ES6 arrow functions
import React, { Component } from 'react';
import './App.css';
import axios from 'axios';
class FieldValues extends Component {
constructor (props){
super(props);
this.state = {
todos: []
}
}
componentDidMount() {
axios.get(`127.0.0.1:8000/api/todos/`)
.then(res => {
this.setState({res.data});
});
}
render(){
console.log(this.state);
}
}
export default FieldValues;
Here's a browser screenshot from my local host serving up json via express and node.
screenshot
And my error - Is it sad to admit that I've been at this for hours now?
Failed to compile.
Error in ./src/App.js Syntax error: Unexpected token, expected , (15:26)
13 | axios.get(`127.0.0.1:8000/api/todos/`)
14 | .then(res => {
> 15 | this.setState({res.data});
| ^
16 | });
17 | }
18 |
Error
@ ./src/index.js 13:11-27