",
6 | "browserslist": {
7 | "production": [
8 | ">0.2%",
9 | "not dead",
10 | "not op_mini all"
11 | ],
12 | "development": [
13 | "last 1 chrome version",
14 | "last 1 firefox version",
15 | "last 1 safari version"
16 | ]
17 | },
18 | "dependencies": {
19 | "@craco/craco": "^6.1.1",
20 | "@tailwindcss/postcss7-compat": "^2.0.3",
21 | "@testing-library/jest-dom": "^5.11.4",
22 | "@testing-library/react": "^11.1.0",
23 | "@testing-library/user-event": "^12.1.10",
24 | "autoprefixer": "^9.8.6",
25 | "postcss": "^7.0.35",
26 | "react": "^17.0.1",
27 | "react-dom": "^17.0.1",
28 | "react-scripts": "4.0.2",
29 | "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.0.3",
30 | "web-vitals": "^1.0.1"
31 | },
32 | "eslintConfig": {
33 | "extends": [
34 | "react-app",
35 | "react-app/jest"
36 | ]
37 | },
38 | "keywords": [
39 | "hooks",
40 | "react"
41 | ],
42 | "license": "MIT",
43 | "private": true,
44 | "scripts": {
45 | "eject": "react-scripts eject",
46 | "start": "craco start",
47 | "build": "craco build",
48 | "start:server": "json-server --watch db.json --port 3001"
49 | },
50 | "devDependencies": {
51 | "husky": ">=4",
52 | "json-server": "^0.16.3",
53 | "lint-staged": ">=10",
54 | "prettier": "2.2.1"
55 | },
56 | "husky": {
57 | "hooks": {
58 | "pre-commit": "lint-staged"
59 | }
60 | },
61 | "lint-staged": {
62 | "*.{js,css,md}": "prettier --write"
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rocketseat-creators-program/react-memoization-hooks-2021-02-16/c6213372b297def845e65e6e8475da68ddb70cde/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
14 |
15 |
19 |
20 |
29 | React App
30 |
31 |
32 |
33 |
34 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rocketseat-creators-program/react-memoization-hooks-2021-02-16/c6213372b297def845e65e6e8475da68ddb70cde/public/logo192.png
--------------------------------------------------------------------------------
/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rocketseat-creators-program/react-memoization-hooks-2021-02-16/c6213372b297def845e65e6e8475da68ddb70cde/public/logo512.png
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/src/App.final.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | import Navbar from "./Components/Navbar";
4 | import { HeadCounter } from "./Components/Counter";
5 | import { FabButton } from "./Components/FabButton";
6 |
7 | import { likesCounter } from "./Services/expensiveCalculation";
8 | import { RepositoryList } from "./Components/RepositortList";
9 |
10 | const SEARCH = "https://api.github.com/search/repositories";
11 |
12 | function App() {
13 | const [dark, setDark] = React.useState(false);
14 | const [totalLikes, setTotalLikes] = React.useState(0);
15 |
16 | const getRepositories = React.useCallback((query) => {
17 | return fetch(`${SEARCH}?q=${query}`);
18 | }, []);
19 |
20 | const toogleDarkmode = () => setDark(!dark);
21 |
22 | const likes = React.useMemo(() => likesCounter(totalLikes), [totalLikes]);
23 |
24 | const theme = React.useMemo(
25 | () => ({
26 | color: dark ? "#fff" : "#333",
27 | navbar: dark ? "#1a202c" : "#e5e7eb",
28 | backgroundColor: dark ? "#333" : "#fff",
29 | }),
30 | [dark]
31 | );
32 |
33 | React.useEffect(() => console.log("Theme updated"), [theme]);
34 |
35 | return (
36 |
37 |
38 |
39 |
40 |
41 |
42 | );
43 | }
44 |
45 | export default App;
46 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from "react";
2 | import { HeadCounter } from "./Components/Counter";
3 | import { FabButton } from "./Components/FabButton";
4 | import Navbar from "./Components/Navbar";
5 | import { likesCounter } from "./Services/expensiveCalculation";
6 |
7 | function App() {
8 | const [totalLikes, setTotalLikes] = useState(0);
9 | const [dark, setDark] = useState(false);
10 |
11 | const likes = likesCounter(totalLikes);
12 |
13 | const theme = {
14 | color: dark ? "#fff" : "#333",
15 | navbar: dark ? "#1a202c" : "#e5e7eb",
16 | backgroundColor: dark ? "#333" : "#fff",
17 | };
18 |
19 | const toogleDarkmode = () => setDark(!dark);
20 |
21 | return (
22 |
23 |
24 |
25 |
26 |
27 | );
28 | }
29 |
30 | export default App;
31 |
--------------------------------------------------------------------------------
/src/Components/Counter.js:
--------------------------------------------------------------------------------
1 | export const HeadCounter = ({ likes }) => (
2 |
3 |
Total Likes {likes}
4 |
5 | );
6 |
--------------------------------------------------------------------------------
/src/Components/FabButton.js:
--------------------------------------------------------------------------------
1 | export const FabButton = (props) => (
2 |
8 | );
9 |
--------------------------------------------------------------------------------
/src/Components/Navbar.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | export default function Navbar({ theme, toogleDarkmode }) {
4 | return (
5 |
38 | );
39 | }
40 |
--------------------------------------------------------------------------------
/src/Components/RepositortList.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { Repository } from "./Repository";
3 |
4 | export const RepositoryList = React.memo(({ getRepositories }) => {
5 | const [items, setItems] = React.useState([]);
6 | const [query, setquery] = React.useState("facebook");
7 |
8 | React.useEffect(() => {
9 | getRepositories(query)
10 | .then((res) => res.json())
11 | .then((data) => setItems((data && data.items) || []));
12 | }, [getRepositories, query]);
13 |
14 | return (
15 |
16 |
22 |
23 | {items &&
24 | items.map((result) => )}
25 |
26 | );
27 | });
28 |
--------------------------------------------------------------------------------
/src/Components/Repository.js:
--------------------------------------------------------------------------------
1 | const Repository = (result) => (
2 |
3 |
15 |
{result.description}
16 |
17 | );
18 |
19 | export { Repository };
--------------------------------------------------------------------------------
/src/Services/expensiveCalculation.js:
--------------------------------------------------------------------------------
1 | /*
2 | Exemplo de uma operação computacional pesada
3 | esse metodo pode travar sua UI
4 | */
5 | export const likesCounter = (likesCounter) => {
6 | for (let index = 0; index < 1000000000; index++) {}
7 | return likesCounter + 1;
8 | };
9 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | @tailwind base;
2 | @tailwind components;
3 | @tailwind utilities;
4 |
5 | .App {
6 | overflow: auto;
7 | height: 100vh;
8 | }
9 | .list {
10 | padding-top: 100px;
11 | }
12 | .toggle__dot {
13 | top: -0.25rem;
14 | left: -0.25rem;
15 | transition: all 0.3s ease-in-out;
16 | }
17 |
18 | input:checked ~ .toggle__dot {
19 | transform: translateX(100%);
20 | background-color: #21e372;
21 | }
22 | .repl-list-item {
23 | padding: 1rem;
24 | margin: 1rem;
25 | background: hsl(0, 0%, 81%);
26 | }
27 |
28 | .float-btn {
29 | position: fixed;
30 | width: 60px;
31 | height: 60px;
32 | bottom: 40px;
33 | right: 40px;
34 | border-radius: 50px;
35 | text-align: center;
36 | box-shadow: 2px 2px 3px #999;
37 | }
38 |
39 | .float-btn-rocket {
40 | background-color: #6b7280;
41 | position: fixed;
42 | width: 60px;
43 | height: 60px;
44 | bottom: 120px;
45 | right: 50px;
46 | border-radius: 50px;
47 | text-align: center;
48 | box-shadow: 2px 2px 3px #999;
49 | }
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import ReactDOM from "react-dom";
3 | import "./index.css";
4 | import App from "./App";
5 | import reportWebVitals from "./reportWebVitals";
6 |
7 | ReactDOM.render(
8 |
9 |
10 | ,
11 | document.getElementById("root")
12 | );
13 |
14 | // If you want to start measuring performance in your app, pass a function
15 | // to log results (for example: reportWebVitals(console.log))
16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
17 | reportWebVitals();
18 |
--------------------------------------------------------------------------------
/src/reportWebVitals.js:
--------------------------------------------------------------------------------
1 | const reportWebVitals = (onPerfEntry) => {
2 | if (onPerfEntry && onPerfEntry instanceof Function) {
3 | import("web-vitals").then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4 | getCLS(onPerfEntry);
5 | getFID(onPerfEntry);
6 | getFCP(onPerfEntry);
7 | getLCP(onPerfEntry);
8 | getTTFB(onPerfEntry);
9 | });
10 | }
11 | };
12 |
13 | export default reportWebVitals;
14 |
--------------------------------------------------------------------------------
/src/setupTests.js:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import "@testing-library/jest-dom";
6 |
--------------------------------------------------------------------------------
/src/start.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from "react";
2 | import { HeadCounter } from "./Components/Counter";
3 | import { FabButton } from "./Components/FabButton";
4 | import Navbar from "./Components/Navbar";
5 | import { likesCounter } from "./Services/expensiveCalculation";
6 |
7 | function App() {
8 | const [totalLikes, setTotalLikes] = useState(0);
9 | const [dark, setDark] = useState(false);
10 |
11 | const likes = likesCounter(totalLikes);
12 |
13 | const theme = {
14 | color: dark ? "#fff" : "#333",
15 | navbar: dark ? "#1a202c" : "#e5e7eb",
16 | backgroundColor: dark ? "#333" : "#fff",
17 | };
18 |
19 | const toogleDarkmode = () => setDark(!dark);
20 |
21 | return (
22 |
23 |
24 |
25 |
26 |
27 | );
28 | }
29 |
30 | export default App;
31 |
--------------------------------------------------------------------------------
/tailwind.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | purge: ["./src/**/*.{js,jsx,ts,tsx}", "./public/index.html"],
3 | darkMode: false, // or 'media' or 'class'
4 | theme: {
5 | extend: {},
6 | },
7 | variants: {
8 | extend: {},
9 | },
10 | plugins: [],
11 | };
12 |
--------------------------------------------------------------------------------