summaryrefslogtreecommitdiff
path: root/src/components/ProxyLatency.js
diff options
context:
space:
mode:
authorhaishanh <[email protected]>2018-11-05 18:32:16 +0800
committerHaishan <[email protected]>2018-11-06 22:37:21 +0800
commit91ecdaa5dd1a65ff0ae944896945c0fe4bc23574 (patch)
tree9f7f476672fae91eca5df9e0ae021b45df950679 /src/components/ProxyLatency.js
parent1adaedcbc551f6beee4e9e0b9fbd94197ebdffe5 (diff)
update: convert more components to function ones
includes Input, Config, SideBard. also removed react-redux Provider
Diffstat (limited to 'src/components/ProxyLatency.js')
-rw-r--r--src/components/ProxyLatency.js55
1 files changed, 25 insertions, 30 deletions
diff --git a/src/components/ProxyLatency.js b/src/components/ProxyLatency.js
index 5d1aaee..96dd26f 100644
--- a/src/components/ProxyLatency.js
+++ b/src/components/ProxyLatency.js
@@ -1,4 +1,4 @@
-import React, { Component } from 'react';
+import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import s0 from './ProxyLatency.module.scss';
@@ -10,35 +10,30 @@ const colorMap = {
na: '#909399'
};
-class C extends Component {
- static propTypes = {
- latency: PropTypes.shape({
- number: PropTypes.number,
- error: PropTypes.string
- })
- };
-
- render() {
- const { latency } = this.props;
- const { number, error } = latency;
- let bg;
-
- if (error !== '') {
- bg = colorMap.na;
- } else if (number < 200) {
- bg = colorMap.good;
- } else if (number < 400) {
- bg = colorMap.normal;
- } else {
- bg = colorMap.bad;
- }
-
- return (
- <span className={s0.proxyLatency} style={{ color: bg }}>
- {error !== '' ? <span>{error}</span> : <span>{number} ms</span>}
- </span>
- );
+function getLabelColor(number, error) {
+ if (error !== '') {
+ return colorMap.na;
+ } else if (number < 200) {
+ return colorMap.good;
+ } else if (number < 400) {
+ return colorMap.normal;
}
+ return colorMap.bad;
}
-export default C;
+export default function ProxyLatency({ latency }) {
+ const { number, error } = latency;
+ const color = useMemo(() => getLabelColor(number, error), [number, error]);
+ return (
+ <span className={s0.proxyLatency} style={{ color }}>
+ {error !== '' ? <span>{error}</span> : <span>{number} ms</span>}
+ </span>
+ );
+}
+
+ProxyLatency.propTypes = {
+ latency: PropTypes.shape({
+ number: PropTypes.number,
+ error: PropTypes.string
+ })
+};