scrimba
React Full Course
Fetching Data From an API
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Fetching Data From an API
by
AboutCommentsNotes
Fetching Data From an API
by
Expand for more info
App.js
run
preview
console
import React, {Component} from "react"


class App extends Component {
constructor()
{
super()
this.state = {
character: ""
}
}
componentDidMount(){
fetch("https://swapi.co/api/people/1")
.then(response => response.json())
.then(data => {
this.setState({
character:data
})
})
}
render(){
return (
<div>
<p>name : {this.state.character.name}</p>
<p>gender: {this.state.character.gender}</p>
<p>mass : {this.state.character.mass}</p>
<p>hair color : {this.state.character.hair_color}</p>
<p>skin color : {this.state.character.skin_color}</p>
</div>
)

}
}

export default App
Console
/index.html
LIVE