Skip to content

Commit c5eaf8e

Browse files
committed
typescript init
1 parent cc0b464 commit c5eaf8e

File tree

13 files changed

+74
-43
lines changed

13 files changed

+74
-43
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@
4545
]
4646
},
4747
"devDependencies": {
48+
"@types/jest": "^29.0.0",
49+
"@types/node": "^18.7.14",
50+
"@types/react": "^18.0.18",
51+
"@types/react-dom": "^18.0.6",
4852
"gh-pages": "^4.0.0",
53+
"typescript": "^4.8.2",
4954
"web-vitals": "^2.1.4"
5055
}
5156
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from "react";
2-
import { render } from "@testing-library/react";
2+
import { render, screen } from "@testing-library/react";
33
import App from "./App";
44

55
test("renders learn react link", () => {
6-
const { getByText } = render(<App />);
7-
const linkElement = getByText(/learn react/i);
6+
render(<App />);
7+
const linkElement = screen.getByText(/learn react/i);
88
expect(linkElement).toBeInTheDocument();
99
});

src/App.js renamed to src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function App() {
1515
const existingTheme = localStorage.getItem("theme");
1616
const [theme, setTheme] = useState(existingTheme || themeOptions.dark);
1717

18-
const setThemeValue = (data) => {
18+
const setThemeValue = (data: string) => {
1919
localStorage.setItem("theme", data);
2020
setTheme(data);
2121
};

src/components/Education.js renamed to src/components/Education.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import React from "react";
2-
import PropTypes from "prop-types";
1+
import { education } from "../types";
32

4-
export default function Education({ education }) {
3+
export default function Education({ education }: screenProps) {
54
return (
65
<div className="card">
76
<div className="card-content">
@@ -41,10 +40,6 @@ export default function Education({ education }) {
4140
);
4241
}
4342

44-
Education.propTypes = {
45-
education: PropTypes.arrayOf(PropTypes.object),
46-
};
47-
48-
Education.defaultProps = {
49-
education: [],
43+
type screenProps = {
44+
education: education[];
5045
};

src/components/Navbar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import PropTypes from "prop-types";
33
import "../../node_modules/bulma-switch/dist/css/bulma-switch.min.css";
4-
import { themeOptions } from "../config.js";
4+
import { themeOptions } from "../config.tsx";
55
import { useTheme } from "../context/theme";
66

77
export default function Navbar({ social: { email, github }, resume }) {
File renamed without changes.

src/index.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/index.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from "react";
2+
import ReactDOM from "react-dom/client";
3+
// import "./index.css";
4+
import App from "./App";
5+
import reportWebVitals from "./reportWebVitals";
6+
7+
const root = ReactDOM.createRoot(
8+
document.getElementById("root") as HTMLElement
9+
);
10+
root.render(
11+
<React.StrictMode>
12+
<App />
13+
</React.StrictMode>
14+
);
15+
16+
// If you want to start measuring performance in your app, pass a function
17+
// to log results (for example: reportWebVitals(console.log))
18+
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
19+
reportWebVitals();

src/reportWebVitals.js renamed to src/reportWebVitals.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const reportWebVitals = (onPerfEntry) => {
1+
import { ReportHandler } from "web-vitals";
2+
3+
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
24
if (onPerfEntry && onPerfEntry instanceof Function) {
35
import("web-vitals").then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
46
getCLS(onPerfEntry);

src/screens/Home.js renamed to src/screens/Home.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import React from "react";
21
import { useQuery, gql } from "@apollo/client";
3-
import PropTypes from "prop-types";
42
import Navbar from "../components/Navbar";
53
import Header from "../components/Header";
64
import Section from "../components/Section";
@@ -12,7 +10,7 @@ import Footer from "../components/Footer";
1210

1311
import portfolio from "../portfolio.json";
1412

15-
const Home = ({ stylesLoaded }) => {
13+
const Home = ({ stylesLoaded }: screenProps) => {
1614
// const { loading, error, data } = useQuery(portfolioQuery);
1715

1816
let portfolioData = portfolio; //getting the json locally to have faster 1st load time on website (free website :p)
@@ -43,7 +41,7 @@ const Home = ({ stylesLoaded }) => {
4341
} = portfolioData;
4442

4543
return (
46-
<React.Fragment>
44+
<>
4745
<Navbar resume={resume} social={social} />
4846
<Header
4947
name={firstName + " " + lastName}
@@ -56,18 +54,10 @@ const Home = ({ stylesLoaded }) => {
5654
<Education education={education} />
5755
<Hobbies hobbies={hobbies} />
5856
<Footer social={social} />
59-
</React.Fragment>
57+
</>
6058
);
6159
};
6260

63-
Home.propTypes = {
64-
stylesLoaded: PropTypes.bool,
65-
};
66-
67-
Home.defaultProps = {
68-
stylesLoaded: false,
69-
};
70-
7161
const portfolioQuery = gql`
7262
query portfolioQuery {
7363
getPortfolio {
@@ -120,4 +110,8 @@ const portfolioQuery = gql`
120110
}
121111
`;
122112

113+
type screenProps = {
114+
stylesLoaded: boolean;
115+
};
116+
123117
export const HomeScreen = Home;

0 commit comments

Comments
 (0)