├── src ├── react-app-env.d.ts ├── index.tsx ├── setupTests.ts ├── components │ ├── Timer.tsx │ ├── TimerPadre.tsx │ ├── Usuario.tsx │ ├── Counter.tsx │ └── ContadorRed.tsx └── App.tsx ├── public ├── favicon.ico ├── logo192.png ├── logo512.png ├── robots.txt ├── manifest.json └── index.html ├── .gitignore ├── README.md ├── tsconfig.json ├── package.json └── .eslintcache /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Klerith/ts-react-hooks/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Klerith/ts-react-hooks/HEAD/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Klerith/ts-react-hooks/HEAD/public/logo512.png -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | 4 | import App from './App'; 5 | 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | -------------------------------------------------------------------------------- /src/setupTests.ts: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | .eslintcahce 4 | 5 | # dependencies 6 | /node_modules 7 | /.pnp 8 | .pnp.js 9 | 10 | # testing 11 | /coverage 12 | 13 | # production 14 | /build 15 | 16 | # misc 17 | .DS_Store 18 | .env.local 19 | .env.development.local 20 | .env.test.local 21 | .env.production.local 22 | 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React + TypeScript 2 | 3 | Este es el repositorio de mi PlayList en YouTube sobre el tema 4 | 5 | ## Cursos que pueden servirte en tu camino 6 | 7 | [Curso completo de React](https://fernando-herrera.com/#/curso/react) 8 | 9 | [Curso de React con Socket.io](https://fernando-herrera.com/#/curso/react-socket) 10 | 11 | [Curso completo de JavaScript](https://fernando-herrera.com/#/curso/js-moderno) 12 | 13 | # Todos mis cursos 14 | 15 | [fernando-herrera.com](https://fernando-herrera.com) 16 | 17 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/components/Timer.tsx: -------------------------------------------------------------------------------- 1 | import { useEffect, useRef, useState } from 'react'; 2 | 3 | type TimerArgs = { 4 | milisegundos: number 5 | } 6 | 7 | export const Timer = ( { milisegundos }: TimerArgs ) => { 8 | 9 | const [segundos, setSegundos] = useState(0); 10 | const ref = useRef(); 11 | 12 | 13 | useEffect( () => { 14 | ref.current && clearInterval( ref.current ); 15 | ref.current = setInterval( () => setSegundos( s => s + 1 ) , milisegundos ); 16 | }, [milisegundos]) 17 | 18 | return ( 19 | <> 20 |

Timer: { segundos }

21 | 22 | ) 23 | } 24 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | 2 | 3 | import { Counter } from './components/Counter'; 4 | import { Usuario } from './components/Usuario'; 5 | 6 | import { TimerPadre } from './components/TimerPadre'; 7 | import { ContadorRed } from './components/ContadorRed'; 8 | 9 | 10 | function App() { 11 | return ( 12 | <> 13 |

React + TypeScript

14 |
15 | 16 |

useState

17 | 18 | 19 | 20 | 21 |

useEffect - useRef

22 |
23 | 24 | 25 | 26 |

useReducer

27 |
28 | 29 | 30 | 31 | 32 | 33 | ); 34 | } 35 | 36 | export default App; 37 | -------------------------------------------------------------------------------- /src/components/TimerPadre.tsx: -------------------------------------------------------------------------------- 1 | 2 | import { useState } from 'react'; 3 | import { Timer } from './Timer'; 4 | 5 | export const TimerPadre = () => { 6 | 7 | const [millisegundos, setMillisegundos] = useState(1000); 8 | 9 | return ( 10 | <> 11 | Milisegundos { millisegundos } 12 | 13 |
14 | 15 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /src/components/Usuario.tsx: -------------------------------------------------------------------------------- 1 | import { useState } from 'react'; 2 | 3 | interface User { 4 | uid: string; 5 | name: string; 6 | } 7 | 8 | 9 | export const Usuario = () => { 10 | 11 | const [user, setUser] = useState(); 12 | 13 | const login = () => { 14 | setUser({ 15 | uid: 'ABC123', 16 | name: 'Fernando Herrera' 17 | }); 18 | } 19 | 20 | return ( 21 |
22 |

Usuario:

23 | 24 | 29 | 30 | { 31 | (!user) 32 | ?
 No hay usuario 
33 | :
 { JSON.stringify( user ) } 
34 | } 35 | 36 | 37 |
38 | ) 39 | } 40 | -------------------------------------------------------------------------------- /src/components/Counter.tsx: -------------------------------------------------------------------------------- 1 | import { useState } from 'react'; 2 | 3 | 4 | export const Counter = () => { 5 | 6 | const [counter, setCounter] = useState(0); 7 | 8 | const incrementar = ( numero: number = 1 ):void => { 9 | setCounter( counter + numero); 10 | } 11 | 12 | 13 | return ( 14 | <> 15 |

Counter:

16 | Valor: { counter } 17 |
18 | 23 | 24 | 29 | 30 | 35 | 36 | ) 37 | } 38 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mi-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.9", 7 | "@testing-library/react": "^11.2.3", 8 | "@testing-library/user-event": "^12.6.2", 9 | "@types/jest": "^26.0.20", 10 | "@types/node": "^12.19.15", 11 | "@types/react": "^16.14.2", 12 | "@types/react-dom": "^16.9.10", 13 | "react": "^17.0.1", 14 | "react-dom": "^17.0.1", 15 | "react-scripts": "4.0.1", 16 | "typescript": "^4.1.3", 17 | "web-vitals": "^0.2.4" 18 | }, 19 | "scripts": { 20 | "start": "react-scripts start", 21 | "build": "react-scripts build", 22 | "test": "react-scripts test", 23 | "eject": "react-scripts eject" 24 | }, 25 | "eslintConfig": { 26 | "extends": [ 27 | "react-app", 28 | "react-app/jest" 29 | ] 30 | }, 31 | "browserslist": { 32 | "production": [ 33 | ">0.2%", 34 | "not dead", 35 | "not op_mini all" 36 | ], 37 | "development": [ 38 | "last 1 chrome version", 39 | "last 1 firefox version", 40 | "last 1 safari version" 41 | ] 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/components/ContadorRed.tsx: -------------------------------------------------------------------------------- 1 | import { useReducer } from 'react'; 2 | 3 | const initialState = { 4 | contador: 10, 5 | } 6 | 7 | type ActionType = 8 | | { type: 'incrementar' } 9 | | { type: 'decrementar' } 10 | | { type: 'custom', payload: number }; 11 | 12 | 13 | 14 | const contadorReducer = ( state: typeof initialState, action: ActionType ) => { 15 | 16 | switch ( action.type ) { 17 | case 'incrementar': 18 | return { 19 | ...state, 20 | contador: state.contador + 1 21 | } 22 | 23 | 24 | case 'decrementar': 25 | return { 26 | ...state, 27 | contador: state.contador - 1 28 | } 29 | 30 | case 'custom': 31 | return { 32 | ...state, 33 | contador: action.payload 34 | } 35 | 36 | 37 | default: 38 | return state; 39 | } 40 | } 41 | 42 | 43 | 44 | 45 | 46 | export const ContadorRed = () => { 47 | 48 | const [ { contador }, dispatch] = useReducer(contadorReducer, initialState); 49 | 50 | 51 | return ( 52 | <> 53 |

Contador: { contador }

54 | 58 | 62 | 63 | 67 | 68 | ) 69 | } 70 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React + TypeScript 28 | 29 | 30 | 31 | 32 | 33 |
34 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /.eslintcache: -------------------------------------------------------------------------------- 1 | [{"C:\\Users\\ferna\\Desktop\\ts-react\\src\\index.tsx":"1","C:\\Users\\ferna\\Desktop\\ts-react\\src\\App.tsx":"2","C:\\Users\\ferna\\Desktop\\ts-react\\src\\components\\Counter.tsx":"3","C:\\Users\\ferna\\Desktop\\ts-react\\src\\components\\Usuario.tsx":"4","C:\\Users\\ferna\\Desktop\\ts-react\\src\\components\\TimerPadre.tsx":"5","C:\\Users\\ferna\\Desktop\\ts-react\\src\\components\\Timer.tsx":"6","C:\\Users\\ferna\\Desktop\\ts-react\\src\\components\\ContadorRed.tsx":"7"},{"size":211,"mtime":1611931522616,"results":"8","hashOfConfig":"9"},{"size":559,"mtime":1611939053186,"results":"10","hashOfConfig":"9"},{"size":903,"mtime":1611931522615,"results":"11","hashOfConfig":"9"},{"size":765,"mtime":1611931522616,"results":"12","hashOfConfig":"9"},{"size":694,"mtime":1611931522616,"results":"13","hashOfConfig":"9"},{"size":561,"mtime":1611931522615,"results":"14","hashOfConfig":"9"},{"size":1538,"mtime":1611940082854,"results":"15","hashOfConfig":"9"},{"filePath":"16","messages":"17","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"zq7ukk",{"filePath":"18","messages":"19","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"20","messages":"21","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"22","messages":"23","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"24","messages":"25","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"26","messages":"27","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"28","messages":"29","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"C:\\Users\\ferna\\Desktop\\ts-react\\src\\index.tsx",[],"C:\\Users\\ferna\\Desktop\\ts-react\\src\\App.tsx",[],"C:\\Users\\ferna\\Desktop\\ts-react\\src\\components\\Counter.tsx",[],"C:\\Users\\ferna\\Desktop\\ts-react\\src\\components\\Usuario.tsx",[],"C:\\Users\\ferna\\Desktop\\ts-react\\src\\components\\TimerPadre.tsx",[],"C:\\Users\\ferna\\Desktop\\ts-react\\src\\components\\Timer.tsx",[],"C:\\Users\\ferna\\Desktop\\ts-react\\src\\components\\ContadorRed.tsx",[]] --------------------------------------------------------------------------------