From 580eb0a449c86d729c5374ee3ebfa3f9bd45fb46 Mon Sep 17 00:00:00 2001 From: E-Liang Tan Date: Sat, 1 Dec 2018 10:52:54 +0800 Subject: [PATCH] Type errors loaders --- .../{GoogleAnalytics.js => GoogleAnalytics.tsx} | 13 +++++++++---- .../common/errors-loaders/{Error.js => Error.tsx} | 11 +++++++++-- .../{NotFoundPage.js => NotFoundPage.tsx} | 0 3 files changed, 18 insertions(+), 6 deletions(-) rename src/components/common/{GoogleAnalytics.js => GoogleAnalytics.tsx} (59%) rename src/components/common/errors-loaders/{Error.js => Error.tsx} (57%) rename src/components/common/errors-loaders/{NotFoundPage.js => NotFoundPage.tsx} (100%) diff --git a/src/components/common/GoogleAnalytics.js b/src/components/common/GoogleAnalytics.tsx similarity index 59% rename from src/components/common/GoogleAnalytics.js rename to src/components/common/GoogleAnalytics.tsx index 4d0a3c0..5645da5 100644 --- a/src/components/common/GoogleAnalytics.js +++ b/src/components/common/GoogleAnalytics.tsx @@ -1,11 +1,16 @@ import React from 'react'; -import { withRouter } from 'react-router-dom'; +import { withRouter, RouteComponentProps } from 'react-router-dom'; import ReactGA from 'react-ga'; +type Props = {} & RouteComponentProps<{}>; + // Adapted from https://stackoverflow.com/a/47385875/5281021 -class GoogleAnalytics extends React.Component { - componentDidUpdate({ location, history }) { - ReactGA.initialize(process.env.REACT_APP_GA_TRACKING_ID, { +class GoogleAnalytics extends React.Component { + componentDidUpdate({ location, history }: Props) { + const { REACT_APP_GA_TRACKING_ID } = process.env; + if (!REACT_APP_GA_TRACKING_ID) return; + + ReactGA.initialize(REACT_APP_GA_TRACKING_ID, { debug: process.env.NODE_ENV === 'development', }); diff --git a/src/components/common/errors-loaders/Error.js b/src/components/common/errors-loaders/Error.tsx similarity index 57% rename from src/components/common/errors-loaders/Error.js rename to src/components/common/errors-loaders/Error.tsx index 9b51ccd..479a898 100644 --- a/src/components/common/errors-loaders/Error.js +++ b/src/components/common/errors-loaders/Error.tsx @@ -1,11 +1,18 @@ import React from 'react'; import styles from './ErrorsLoaders.module.scss'; -export default function Error({ title, message }) { +interface Props { + title: string; + message: string; +} + +const Error: React.FunctionComponent = ({ title, message }) => { return (

{title}

{message}
); -} +}; + +export default Error; diff --git a/src/components/common/errors-loaders/NotFoundPage.js b/src/components/common/errors-loaders/NotFoundPage.tsx similarity index 100% rename from src/components/common/errors-loaders/NotFoundPage.js rename to src/components/common/errors-loaders/NotFoundPage.tsx