-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.jsx
62 lines (52 loc) · 1.09 KB
/
index.jsx
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import _ from 'lodash';
import React, { Component } from 'react';
import styled from 'styled-components';
const Container = styled.section`
border-radius: 5px;
background: #bbb;
color: #402726;
`;
const List = styled.ul`
color: #fff;
padding: 5px;
`;
const Item = styled.li`
display: ${ props => props.isShow ? 'block' : 'none' }
`;
class Newsticker extends Component {
constructor(props) {
super(props);
this.state = { seconds: 0 };
}
componentDidMount() {
this.interval = setInterval(() => this._tick(), 3000);
}
_tick() {
this.setState(prevState => ({
seconds: prevState.seconds + 1
}));
}
_renderNewsList() {
const len = this.props.news.length;
return _.map(this.props.news, (item, index) => {
return (
<Item
key={ index }
isShow={ this.state.seconds % len === index }
>
{ item }
</Item>
);
});
}
render() {
return (
<Container>
<List>
{ this._renderNewsList() }
</List>
</Container>
);
}
}
export default Newsticker;