From 9bea9c2e25fce7de1d1608f17887d37a3f78763a Mon Sep 17 00:00:00 2001 From: kohei Date: Mon, 19 Nov 2018 17:26:42 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20Stateless=20Functional=20Component?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/kaburi.jsx | 34 +++++++++++-------------- components/percentage.jsx | 52 ++++++++++++++++++--------------------- 2 files changed, 39 insertions(+), 47 deletions(-) diff --git a/components/kaburi.jsx b/components/kaburi.jsx index a395238..dc7b0cf 100644 --- a/components/kaburi.jsx +++ b/components/kaburi.jsx @@ -1,20 +1,16 @@ -import { Component } from "react"; +export default ({ activity }) => { + const kaburiActivity = activity.filter(a => a.ch === "kaburi"); + const count = kaburiActivity.length; + const time = kaburiActivity + .map(a => a.endTime - a.startTime) + .reduce((a, c) => a + c, 0); -export default class extends Component { - render() { - const activity = this.props.activity.filter(a => a.ch === "kaburi"); - const count = activity.length; - const time = activity - .map(a => a.endTime - a.startTime) - .reduce((a, c) => a + c, 0); - - return ( -
-
かぶり回数
-
{count}
-
かぶり時間 (ms)
-
{time}
-
- ); - } -} + return ( +
+
かぶり回数
+
{count}
+
かぶり時間 (ms)
+
{time}
+
+ ); +}; diff --git a/components/percentage.jsx b/components/percentage.jsx index d249a5a..038e957 100644 --- a/components/percentage.jsx +++ b/components/percentage.jsx @@ -1,29 +1,25 @@ -import { Component } from "react"; +export default ({ activity }) => { + const leftActivity = activity + .filter(a => a.ch === "l") + .map(a => a.endTime - a.startTime) + .reduce((a, c) => a + c, 0); + const rightActivity = activity + .filter(a => a.ch === "r") + .map(a => a.endTime - a.startTime) + .reduce((a, c) => a + c, 0); -export default class extends Component { - render() { - const leftActivity = this.props.activity - .filter(a => a.ch === "l") - .map(a => a.endTime - a.startTime) - .reduce((a, c) => a + c, 0); - const rightActivity = this.props.activity - .filter(a => a.ch === "r") - .map(a => a.endTime - a.startTime) - .reduce((a, c) => a + c, 0); - - return ( -
-
会話時間 (ms)
-
{leftActivity + rightActivity}
-
会話の割合
-
- 左{" "} - - {leftActivity / (leftActivity + rightActivity)} - {" "} - 右 -
-
- ); - } -} + return ( +
+
会話時間 (ms)
+
{leftActivity + rightActivity}
+
会話の割合
+
+ 左{" "} + + {leftActivity / (leftActivity + rightActivity)} + {" "} + 右 +
+
+ ); +};