Skip to content

Commit 93564e6

Browse files
committed
Added setAlert functionto catch the call from search.js
1 parent 8287c23 commit 93564e6

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/App.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import axios from 'axios'
33

44

55
import Navbar from './components/layout/Navbar'
6+
import Alert from './components/layout/Alert'
67
import Users from './components/users/Users'
78
import Search from './components/users/Search'
89

@@ -11,7 +12,8 @@ import './App.css';
1112
class App extends Component {
1213
state={
1314
users: [],
14-
loading: false
15+
loading: false,
16+
alert: null
1517
}
1618

1719
async componentDidMount(){
@@ -37,16 +39,28 @@ class App extends Component {
3739
loading: false
3840
})
3941
}
42+
43+
setAlert = (message, type) =>{
44+
this.setState({
45+
alert:{
46+
message: message,
47+
type: type
48+
}
49+
})
50+
setTimeout(()=> this.setState({alert: null}), 3000)
51+
}
4052

4153
render(){
4254
return (
4355
<div >
4456
<Navbar title="Github Finder" icon="fab fa-github"/>
4557
<div className="container">
58+
<Alert alert={this.state.alert}/>
4659
<Search
4760
searchUsers={this.searchUsers}
4861
clearUsers={this.clearUsers}
49-
showClear={this.state.users.length > 0 ? true : false} />
62+
showClear={this.state.users.length > 0 ? true : false}
63+
setAlert={this.setAlert} />
5064
<Users
5165
loading={this.state.loading}
5266
users={this.state.users} />

0 commit comments

Comments
 (0)