-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (30 loc) · 851 Bytes
/
index.js
File metadata and controls
38 lines (30 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import NewsList from './components/news_list';
// COMPONENTS
import Header from './components/header';
import JSON from './db.json';
class App extends Component {
constructor(props){
super(props);
this.state = {
news:JSON,
filtered:JSON
}
}
filterNews(keywords){
let filtered =this.state.news.filter((item)=>{
return item.title.indexOf(keywords) > -1;
})
this.setState({filtered})
}
render(){
return(
<div>
<Header newsSearch={keywords=>this.filterNews(keywords)}/>
<NewsList news={this.state.filtered}/>
</div>
);
}
}
ReactDOM.render(<App/>, document.getElementById('root'));