Skip to content

Commit

Permalink
migrate: @/index.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
yumincho authored and sboh1214 committed Mar 14, 2024
1 parent 09569bb commit 6738c72
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<noscript> You need to enable JavaScript to run this app. </noscript>
<div id="root"></div>
<div id="popup-root"></div>
<script type="module" src="/src/index.jsx"></script>
<script type="module" src="/src/index.tsx"></script>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
Expand Down
27 changes: 24 additions & 3 deletions src/index.jsx → src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,29 @@ i18n
formatSeparator: ',',
format: (value, formatting, lng) => {
if (value instanceof Date) {
return moment(value).locale(lng).format(formatting);
return moment(value)
.locale(lng ?? '')
.format(formatting);
}
return value.toString();
},
},
});

import axios from 'axios';

declare module 'axios' {
export interface AxiosRequestConfig {
metadata: {
gaCategory: string;
gaVariable: string;
startTime?: Date;
endTime?: Date;
duration?: number;
};
}
}

import Qs from 'qs';
import { API_URL } from './const';

Expand Down Expand Up @@ -71,7 +86,8 @@ axios.interceptors.response.use(
(response) => {
response.config.metadata.endTime = new Date();
response.config.metadata.duration =
response.config.metadata.endTime - response.config.metadata.startTime;
response.config.metadata.endTime.getTime() - response.config.metadata.startTime!.getTime();

return response;
},
(error) => {
Expand All @@ -87,7 +103,12 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

const container = document.getElementById('root');
const container: HTMLElement | null = document.getElementById('root');

if (!container) {
throw new Error('There must be root element');
}

const root = ReactDOM.createRoot(container); // createRoot(container!) if you use TypeScript
root.render(
<BrowserRouter>
Expand Down

0 comments on commit 6738c72

Please sign in to comment.