Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5a86e5c

Browse files
authored
Fetch data from API
1 parentc597a2e commit5a86e5c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

‎README.md‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,41 @@ function isJson(str) {
505505
}
506506
```
507507
508+
# Fetch data from API REACT
509+
```REACTJS
510+
importReact, {Component}from'react'
511+
512+
exportdefaultclassStarWarsextendsComponent {
513+
constructor(){
514+
super()
515+
this.state= {
516+
character: {},
517+
isLoading:false
518+
}
519+
}
520+
521+
componentDidMount(){
522+
this.setState({isLoading:true})
523+
fetch("https://swapi.co/api/people/1")
524+
.then(response=>response.json())
525+
.then(data=> (
526+
this.setState({
527+
isLoading:false,
528+
character: data
529+
})
530+
))
531+
}
508532

533+
534+
render(){
535+
consttext=this.state.isLoading?"People data is loading...":this.state.character.name
536+
return(
537+
<div>
538+
<p>{text}</p>
539+
</div>
540+
)
541+
}
542+
}
543+
```
509544
510545

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp