File tree Expand file tree Collapse file tree 3 files changed +60
-3
lines changed Expand file tree Collapse file tree 3 files changed +60
-3
lines changed Original file line number Diff line number Diff line change 1- import React from "react" ;
1+ import React , { useState , useEffect } from "react" ;
22import "./App.css" ;
33import "bootstrap/dist/css/bootstrap.min.css" ;
44import { Container } from "react-bootstrap" ;
5+ import IssueList from "./components/IssueList" ;
6+ import SearchForm from "./components/SearchForm" ;
57
68function App ( ) {
9+ const [ issues , setIssues ] = useState ( [ ] ) ;
10+ const [ searchTerm , setSearchTerm ] = useState ( "" ) ;
11+ const [ url , setUrl ] = useState (
12+ "https://api.github.com/repos/octocat/hello-world/issues"
13+ ) ;
14+ useEffect ( ( ) => {
15+ async function fetchData ( ) {
16+ let data = await fetch ( url ) ;
17+ let json = await data . json ( ) ;
18+ setIssues ( json ) ;
19+ }
20+ fetchData ( ) ;
21+ } , [ url ] ) ;
22+
23+ const handleClick = ( ) => {
24+ setUrl ( `https://api.github.com/repos/${ searchTerm } /issues` ) ;
25+ } ;
26+
27+ const handleChange = ( e ) => {
28+ setSearchTerm ( e . target . value ) ;
29+ } ;
30+
731 return (
832 < Container >
933 < h1 className = "text-center" > GitHub Issues Browser</ h1 >
10- < p > Fill in files from /src/components.</ p >
34+ < SearchForm
35+ handleChange = { handleChange }
36+ handleClick = { handleClick }
37+ searchTerm = { searchTerm }
38+ />
39+ < IssueList issues = { issues } />
1140 </ Container >
1241 ) ;
1342}
1443
15- export default App ;
44+ export default App ;
Original file line number Diff line number Diff line change 1+ import React from "react" ;
2+
3+ const IssueList = ( { issues } ) => {
4+ return (
5+ < div >
6+ < h2 > Issue list</ h2 >
7+ < ul >
8+ { issues . map ( ( i ) => (
9+ < li key = { i . id } > { i . title } </ li >
10+ ) ) }
11+ </ ul >
12+ </ div >
13+ ) ;
14+ } ;
15+
16+ export default IssueList ;
Original file line number Diff line number Diff line change 1+ import React from "react" ;
2+
3+ const SearchForm = ( { handleChange, searchTerm, handleClick } ) => {
4+ return (
5+ < div >
6+ < input type = "text" onChange = { handleChange } value = { searchTerm } />
7+ < button onClick = { handleClick } > Search</ button >
8+ </ div >
9+ ) ;
10+ } ;
11+
12+ export default SearchForm ;
You can’t perform that action at this time.
0 commit comments