|
1 | | -import React from 'react'; |
| 1 | +import { useEffect, useRef } from 'react'; |
2 | 2 | import {Icon} from 'semantic-ui-react'; |
3 | 3 |
|
4 | | -export default class NoticeLinks extends React.Component { |
| 4 | +export default function NoticeLinks() { |
| 5 | + const listEl = useRef(null); |
| 6 | + useSliderEffect(listEl); |
5 | 7 |
|
6 | | - list = React.createRef(); |
7 | | - active = 1; |
8 | | - constructor(props) { |
9 | | - super(props); |
10 | | - } |
| 8 | + return ( |
| 9 | + <div className='notice-links' ref={listEl}> |
| 10 | + <a className='animated fadeIn show' target='_blank' rel='noopener noreferrer' |
| 11 | + href='https://github.com/unbug/snts'> |
| 12 | + <Icon name='heartbeat'/> SAY NO TO SUICIDE PUBLIC LICENSE |
| 13 | + </a> |
| 14 | + <a className='animated fadeIn' target='_blank' rel='noopener noreferrer' href='//mihtool.com/'> |
| 15 | + <Icon name='code'/> [MIHTool] iOS 上调试和优化页面的工具 |
| 16 | + </a> |
| 17 | + <a className='animated fadeIn' target='_blank' rel='noopener noreferrer' href='https://www.wasmrocks.com/'> |
| 18 | + <Icon name='hand rock'/> WebAssembly Rocks |
| 19 | + </a> |
| 20 | + <a className='animated fadeIn' target='_blank' rel='noopener noreferrer' |
| 21 | + href='https://github.com/unbug/react-native-train/blob/master/README.md'> |
| 22 | + <Icon name='video'/> [开源] React Native 开发培训资料和视频 |
| 23 | + </a> |
| 24 | + <a className='animated fadeIn' target='_blank' rel='noopener noreferrer' |
| 25 | + href='https://www.zhihu.com/question/27097399/answer/78619944'> |
| 26 | + [知乎] 编程的时候命名方法或变量词穷了怎么办? |
| 27 | + </a> |
| 28 | + </div> |
| 29 | + ) |
| 30 | +} |
11 | 31 |
|
12 | | - componentDidMount() { |
13 | | - setInterval(() => this.renderItem(this.list.current.children), 10000); |
14 | | - } |
| 32 | +function useSliderEffect(el) { |
| 33 | + useEffect(() => { |
| 34 | + const timer = setInterval(() => renderItem(el.current.children), 10000); |
| 35 | + return () => clearInterval(timer); |
| 36 | + }, []); // pass [] to run an effect and clean it up only once |
15 | 37 |
|
16 | | - renderItem(list) { |
| 38 | + let active = 1; |
| 39 | + function renderItem(list) { |
17 | 40 | Array.prototype.forEach.call(list, (item, i) => { |
18 | | - if (i === this.active) { |
| 41 | + if (i === active) { |
19 | 42 | item.classList.add('show'); |
20 | 43 | } else { |
21 | 44 | item.classList.remove('show'); |
22 | 45 | } |
23 | 46 | }); |
24 | | - this.active++; |
25 | | - if (this.active >= list.length) { |
26 | | - this.active = 0; |
| 47 | + active++; |
| 48 | + if (active >= list.length) { |
| 49 | + active = 0; |
27 | 50 | } |
28 | 51 | } |
29 | | - |
30 | | - render() { |
31 | | - return ( |
32 | | - <div className='notice-links' ref={this.list}> |
33 | | - <a className='animated fadeIn show' target='_blank' rel='noopener noreferrer' |
34 | | - href='https://github.com/unbug/snts'> |
35 | | - <Icon name='heartbeat'/> SAY NO TO SUICIDE PUBLIC LICENSE |
36 | | - </a> |
37 | | - <a className='animated fadeIn' target='_blank' rel='noopener noreferrer' href='//mihtool.com/'> |
38 | | - <Icon name='code'/> [MIHTool] iOS 上调试和优化页面的工具 |
39 | | - </a> |
40 | | - <a className='animated fadeIn' target='_blank' rel='noopener noreferrer' href='https://www.wasmrocks.com/'> |
41 | | - <Icon name='hand rock'/> WebAssembly Rocks |
42 | | - </a> |
43 | | - <a className='animated fadeIn' target='_blank' rel='noopener noreferrer' |
44 | | - href='https://github.com/unbug/react-native-train/blob/master/README.md'> |
45 | | - <Icon name='video'/> [开源] React Native 开发培训资料和视频 |
46 | | - </a> |
47 | | - <a className='animated fadeIn' target='_blank' rel='noopener noreferrer' |
48 | | - href='https://www.zhihu.com/question/27097399/answer/78619944'> |
49 | | - [知乎] 编程的时候命名方法或变量词穷了怎么办? |
50 | | - </a> |
51 | | - </div> |
52 | | - ) |
53 | | - } |
54 | 52 | } |
0 commit comments