├── .gitignore ├── aula-3-lets-input-react ├── live │ └── cep-api │ │ ├── public │ │ ├── robots.txt │ │ ├── favicon.ico │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ └── index.html │ │ ├── src │ │ ├── setupTests.js │ │ ├── App.test.js │ │ ├── App.js │ │ ├── index.css │ │ ├── index.js │ │ ├── App.css │ │ ├── logo.svg │ │ ├── form │ │ │ └── AddressForm.js │ │ └── serviceWorker.js │ │ ├── .gitignore │ │ ├── package.json │ │ └── README.md └── README.md ├── aula-5-lets-hooks-it-all ├── .DS_Store ├── live │ └── redux-hooks-demo │ │ ├── public │ │ ├── robots.txt │ │ ├── favicon.ico │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ └── index.html │ │ ├── src │ │ ├── store │ │ │ └── index.js │ │ ├── actions │ │ │ └── index.js │ │ ├── setupTests.js │ │ ├── App.test.js │ │ ├── reducers │ │ │ └── todos.js │ │ ├── App.js │ │ ├── index.css │ │ ├── containers │ │ │ ├── ToDoList.jsx │ │ │ └── AddTodo.jsx │ │ ├── index.js │ │ ├── App.css │ │ ├── logo.svg │ │ └── serviceWorker.js │ │ ├── .gitignore │ │ ├── package.json │ │ └── README.md ├── README.md └── recursos │ └── me-transforme-em-funcao.js ├── aula-6-lets-request-data └── README.md ├── aula-1-javascript-avancado ├── readFile.js ├── respostas │ └── challenges-result.md └── README.md ├── aula-4-lets-context-everything └── README.md ├── aula-2-lets-react └── README.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | **/**/node_modules 2 | -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WoMakersCode/react-bootcamp/HEAD/aula-5-lets-hooks-it-all/.DS_Store -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WoMakersCode/react-bootcamp/HEAD/aula-3-lets-input-react/live/cep-api/public/favicon.ico -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WoMakersCode/react-bootcamp/HEAD/aula-3-lets-input-react/live/cep-api/public/logo192.png -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WoMakersCode/react-bootcamp/HEAD/aula-3-lets-input-react/live/cep-api/public/logo512.png -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WoMakersCode/react-bootcamp/HEAD/aula-5-lets-hooks-it-all/live/redux-hooks-demo/public/favicon.ico -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WoMakersCode/react-bootcamp/HEAD/aula-5-lets-hooks-it-all/live/redux-hooks-demo/public/logo192.png -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WoMakersCode/react-bootcamp/HEAD/aula-5-lets-hooks-it-all/live/redux-hooks-demo/public/logo512.png -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/src/store/index.js: -------------------------------------------------------------------------------- 1 | import { createStore } from 'redux' 2 | import todos from '../reducers/todos' 3 | 4 | const store = createStore(todos) 5 | 6 | export default store -------------------------------------------------------------------------------- /aula-6-lets-request-data/README.md: -------------------------------------------------------------------------------- 1 | # Let's request data 2 | 3 | Vimos como fazer integração da nossa aplicação e sobre gerecimento de rotas 4 | 5 | 6 | [slides](https://docs.google.com/presentation/d/1J7fZjgv3ZT72pyM3ZKkoEf9KQ2ssp9OTE3pbdQFmNIw/edit?usp=sharing) -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/src/actions/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * action types 3 | */ 4 | 5 | export const ADD_TODO = 'ADD_TODO' 6 | 7 | /* 8 | * action creators 9 | */ 10 | 11 | export function addTodo(item) { 12 | return { type: ADD_TODO, item } 13 | } -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/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/extend-expect'; 6 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/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/extend-expect'; 6 | -------------------------------------------------------------------------------- /aula-1-javascript-avancado/readFile.js: -------------------------------------------------------------------------------- 1 | // let fs = require('fs'); 2 | 3 | // fs.readFile('test.txt', 'utf8', function(error, data) { 4 | // if (error) { 5 | // throw error; 6 | // } 7 | 8 | // console.log("Asynchronous message. Content of test.txt:", data); 9 | // }); 10 | 11 | // console.log('Synchronous message'); -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | const { getByText } = render(); 7 | const linkElement = getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | const { getByText } = render(); 7 | const linkElement = getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import logo from './logo.svg'; 3 | import './App.css'; 4 | import 'bootstrap/dist/css/bootstrap.min.css'; 5 | import AddressForm from './form/AddressForm' 6 | 7 | function App() { 8 | return ( 9 |
10 | 11 |
12 | ); 13 | } 14 | 15 | export default App; 16 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/src/reducers/todos.js: -------------------------------------------------------------------------------- 1 | const INITIAL_STATE = { 2 | toDoList:['limpar a casa'] 3 | } 4 | 5 | function todos(state=INITIAL_STATE, action){ 6 | switch(action.type){ 7 | case 'ADD_TODO': 8 | return {...state, toDoList:[ ...state.toDoList, action.item]} 9 | default: 10 | return state 11 | } 12 | } 13 | 14 | export default todos -------------------------------------------------------------------------------- /aula-4-lets-context-everything/README.md: -------------------------------------------------------------------------------- 1 | # Let's context everything 2 | 3 | Vimos como funciona o contexto no React e começamos a mexer com Redux. 4 | 5 | link para a os [slides](https://docs.google.com/presentation/d/1qo0z5L5vHOyf7PySLKop0dOObrOvDtnyb7lqihAYSeI/edit?usp=sharing) 6 | 7 | link para o github da professora com algum conteúdo da aula [github](https://github.com/brenndafarinha/context-api-react) 8 | -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Provider } from 'react-redux' 3 | import store from './store' 4 | import ToDoList from './containers/ToDoList' 5 | import AddTodo from './containers/AddTodo' 6 | 7 | function App() { 8 | return ( 9 | 10 |

Todo list

11 | 12 | 13 |
14 | ); 15 | } 16 | 17 | export default App; 18 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/src/containers/ToDoList.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { useSelector } from 'react-redux' 3 | 4 | const ToDoList = () => { 5 | const todoList = useSelector(state => state.toDoList) 6 | return( 7 | 13 | ) 14 | } 15 | 16 | export default ToDoList -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/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 * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | 9 | // If you want your app to work offline and load faster, you can change 10 | // unregister() to register() below. Note this comes with some pitfalls. 11 | // Learn more about service workers: https://bit.ly/CRA-PWA 12 | serviceWorker.unregister(); 13 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/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 * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | 9 | // If you want your app to work offline and load faster, you can change 10 | // unregister() to register() below. Note this comes with some pitfalls. 11 | // Learn more about service workers: https://bit.ly/CRA-PWA 12 | serviceWorker.unregister(); 13 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/src/containers/AddTodo.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react' 2 | import { useDispatch } from 'react-redux' 3 | import { addTodo } from '../actions' 4 | 5 | const ToDoList = () => { 6 | const [todoItem, setTodoItem] = useState('') 7 | const dispatch = useDispatch() 8 | 9 | const addTodoItem = () => dispatch(addTodo(todoItem)) 10 | 11 | return( 12 |
13 | setTodoItem(value)}/> 14 | 15 |
16 | 17 | ) 18 | } 19 | 20 | export default ToDoList -------------------------------------------------------------------------------- /aula-2-lets-react/README.md: -------------------------------------------------------------------------------- 1 | # 2 - Let's React 2 | 3 | Nesta aula finalmente entramos na biblioteca react, instalamos, conhecemos seus conceitos como Props, State, Componentes e entendemos o que é "Pensar do jeito React". 4 | 5 | link para a os [slides](https://docs.google.com/presentation/d/1fV0px6hqFjo7ZePC5SAQ1dKSPDD2IVerRmmxZJrOb0U/edit?usp=sharing) 6 | 7 | link para exemplo de componentes com classes da prof Rebecca [github](https://github.com/ArantesRebecca/react-class) 8 | 9 | # Challenge 10 | 11 | O desafio foi pensar em react (rsrs), identificar componentes em alguns sites e transformá-los em componentes com funções, states e props -------------------------------------------------------------------------------- /aula-3-lets-input-react/README.md: -------------------------------------------------------------------------------- 1 | # Let's input React 2 | 3 | Nesta aula fizemos a revisão do thinking react e começamos a lidar com eventos e manipulação de valores nos componentes, muitos deles formulários. 4 | 5 | link para a os [slides](https://docs.google.com/presentation/d/1u0TiKkOQdWTHt1mAICqbjYJSMbd8IT49BVgtL7F7rPQ/edit?usp=sharing) 6 | 7 | link para o exemplo do register form da prof Rebecca [github](https://github.com/ArantesRebecca/register-form) 8 | 9 | # Challenge 10 | 11 | Fazer um formlário de cadastro de alunas (slide 11) e validar se todos os campos estão preenchidos antes de dar submit, caso não esteja deve exibir a mensagem para o usuário -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/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 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/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 | -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/README.md: -------------------------------------------------------------------------------- 1 | # Let's hooks it all 2 | 3 | - Transição de Classes para funçoes 4 | - funções que substituem algumas funcionalidades que antes dependíamos de classes como useState e useEffect 5 | - Custom hooks 6 | - Fetch api para listar valores de uma api 7 | - Revisão de redux (tá dificil rsrs) 8 | 9 | link para a os [slides](https://docs.google.com/presentation/d/1d4gzea82J5Xuizp4ZFsQACtV4zY2gmq0w2M3tG8_Lt8/edit?usp=sharing) 10 | 11 | # Challenge 12 | 13 | ### Listar filmes do estudio ghibli 14 | Link para o github da professora com o exercício [github](https://github.com/brenndafarinha/studio-ghibli-challenge) 15 | 16 | ### Refatorar um componente de Classe para Função 17 | [Arquivo para refatorar](./recursos/me-transforme-em-funcao.js) 18 | 19 | ### Fazer uma todo list com redux a partir da documentação 20 | 21 | [Documentação do Redux](https://redux.js.org/basics/example) 22 | [Projeto base para construir o todolist](https://github.com/brenndafarinha/todo-list-challenge) -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "redux-demo", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^4.2.4", 7 | "@testing-library/react": "^9.3.2", 8 | "@testing-library/user-event": "^7.1.2", 9 | "react": "^16.13.0", 10 | "react-dom": "^16.13.0", 11 | "react-redux": "^7.2.0", 12 | "react-scripts": "3.4.0", 13 | "redux": "^4.0.5" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": "react-app" 23 | }, 24 | "browserslist": { 25 | "production": [ 26 | ">0.2%", 27 | "not dead", 28 | "not op_mini all" 29 | ], 30 | "development": [ 31 | "last 1 chrome version", 32 | "last 1 firefox version", 33 | "last 1 safari version" 34 | ] 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cep-api", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^4.2.4", 7 | "@testing-library/react": "^9.3.2", 8 | "@testing-library/user-event": "^7.1.2", 9 | "react": "^16.13.0", 10 | "react-dom": "^16.13.0", 11 | "react-scripts": "3.4.0" 12 | }, 13 | "scripts": { 14 | "start": "react-scripts start", 15 | "build": "react-scripts build", 16 | "test": "react-scripts test", 17 | "eject": "react-scripts eject" 18 | }, 19 | "eslintConfig": { 20 | "extends": "react-app" 21 | }, 22 | "browserslist": { 23 | "production": [ 24 | ">0.2%", 25 | "not dead", 26 | "not op_mini all" 27 | ], 28 | "development": [ 29 | "last 1 chrome version", 30 | "last 1 firefox version", 31 | "last 1 safari version" 32 | ] 33 | }, 34 | "devDependencies": { 35 | "bootstrap": "^4.4.1", 36 | "reactstrap": "^8.4.1" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Bootcamp WoMakersCode 2 | 3 | - [aula1](./aula-1-javascript-avancado) 4 | - [aula2](./aula-2-lets-react) 5 | - [aula3](./aula-3-lets-input-react) 6 | - [aula4](./aula-4-lets-context-everything) 7 | - [aula5](./aula-5-lets-hooks-it-all) 8 | - [aula6](./aula-6-lets-request-data) 9 | 10 | # Desafios para serem entregues 11 | - Formulário de cadastro de alunas, (os campos precisam estar validados, não pode dar submit sem preencher tudo) 12 | [desafio](./aula-3-lets-input-react) 13 | 14 | - Formulário de CEP que preenche todos os campos quando a API responde o enredereço 15 | [desafio](./aula-3-lets-input-react/live/cep-api) 16 | 17 | - Consumir API do estudio Ghibli 18 | [desafio](./aula-5-lets-hooks-it-all) 19 | 20 | - To Do List com redux 21 | [desafio](./aula-5-lets-hooks-it-all) 22 | 23 | 24 | # Projetos finais 25 | 26 | Abaixo estão os projetos finais do bootcamp, a turma foi dividida em 4 times e cada uma está gerenciando o projeto no github com práticas como abrir issues, pull requests e code review. 27 | Para acompanhar basta clicar nos repositórios abaixo 28 | 29 | - [Call for papers](https://github.com/React-Bootcamp-WoMarkersCode/call-of-papers) 30 | - [Sorteador de brindes](https://github.com/React-Bootcamp-WoMarkersCode/gift-drawer) 31 | - [Gerador de certificado](https://github.com/React-Bootcamp-WoMarkersCode/certificate-generator) 32 | - [Plataforma para Speed hiring](https://github.com/React-Bootcamp-WoMarkersCode/cv-speed-hiring) -------------------------------------------------------------------------------- /aula-1-javascript-avancado/respostas/challenges-result.md: -------------------------------------------------------------------------------- 1 | ### Challenge 1 2 | ``` 3 | function job1(callback){ 4 | setTimeout(function(){ 5 | callback(); 6 | },2000) 7 | } 8 | 9 | function job(callback1, callback2) { 10 | job1(callback1) 11 | 12 | setTimeout(function(){ 13 | callback2() 14 | setTimeout(function(){ 15 | callback2() 16 | setTimeout(function(){ 17 | callback2() 18 | }, 1000) 19 | }, 1000) 20 | }, 1000) 21 | 22 | } 23 | 24 | module.exports = job; 25 | ``` 26 | 27 | como a Patricia resovleu 28 | 29 | ``` 30 | function job(callback1, callback2) { 31 | return new Promise(resolve => { 32 | setTimeout(() => callback1(), 2000); 33 | setTimeout(() => callback2(), 1000); 34 | setTimeout(() => callback2(), 2000); 35 | setTimeout(() => callback2(), 3000); 36 | }); 37 | } 38 | ``` 39 | 40 | ### Challenge 2 41 | 42 | function job() { 43 | return new Promise((resolve) => { 44 | setTimeout(() => { 45 | resolve('hello world') 46 | }, 2000) 47 | }) 48 | } 49 | 50 | module.exports = job; 51 | 52 | ### challenge 4 53 | 54 | async function job(result, database, errorManager) { 55 | try{ 56 | const id = await result 57 | const info = await database.get(id) 58 | return info.name 59 | }catch(error){ 60 | errorManager.notify(error); 61 | throw error; 62 | } 63 | } 64 | 65 | module.exports = job; -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/recursos/me-transforme-em-funcao.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { Form, Button } from 'semantic-react-ui' 3 | 4 | class ExampleComponent extends Component { 5 | 6 | state = { 7 | showForm: false, 8 | email: "", 9 | name: this.props.name 10 | } 11 | 12 | componentDidMount() { 13 | 14 | /* algum fetch de dado que a gente quer rodar somente uma vez 15 | .................... 16 | */ 17 | } 18 | 19 | handleChange = (e) => { 20 | this.setState({ 21 | [e.target.name]: e.target.value 22 | }) 23 | } 24 | 25 | handleSubmit = (e) => { 26 | e.preventDefault() 27 | 28 | /* executa alguma request 29 | .................... 30 | */ 31 | } 32 | 33 | 34 | toggleShowForm = (e) => { 35 | 36 | this.setState({ 37 | showForm: !this.state.showForm, 38 | }) 39 | } 40 | 41 | // RENDERS ------------------------------ 42 | 43 | renderForm() { 44 | return
45 | 46 | 47 | Submit! 48 | 49 | } 50 | 51 | // RENDER -------------------------------- 52 | render() { 53 | 54 | return ( 55 |
56 | {this.state.showForm ? this.renderForm() 57 | : 58 |

Hi, {this.state.name}

59 | 60 |
61 | } 62 |
63 | ) 64 | } 65 | } 66 | 67 | export default ExampleComponent 68 | 69 | -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `yarn start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `yarn test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `yarn build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `yarn eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | 46 | ### Code Splitting 47 | 48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 49 | 50 | ### Analyzing the Bundle Size 51 | 52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 53 | 54 | ### Making a Progressive Web App 55 | 56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 57 | 58 | ### Advanced Configuration 59 | 60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 61 | 62 | ### Deployment 63 | 64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 65 | 66 | ### `yarn build` fails to minify 67 | 68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 69 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `yarn start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `yarn test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `yarn build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `yarn eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | 46 | ### Code Splitting 47 | 48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 49 | 50 | ### Analyzing the Bundle Size 51 | 52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 53 | 54 | ### Making a Progressive Web App 55 | 56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 57 | 58 | ### Advanced Configuration 59 | 60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 61 | 62 | ### Deployment 63 | 64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 65 | 66 | ### `yarn build` fails to minify 67 | 68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 69 | -------------------------------------------------------------------------------- /aula-1-javascript-avancado/README.md: -------------------------------------------------------------------------------- 1 | # 1 - Javascript Avançado 2 | 3 | [slides](https://docs.google.com/presentation/d/1EkLKA7qfpbH1Rc2lkl43h5BZ0X2Uv5O-uoEzc1Z1qKs/edit?usp=sharing) 4 | 5 | ## Promises - Chaining 6 | ``` 7 | var promise = job1(); 8 | 9 | promise 10 | 11 | .then(function(data1) { 12 | console.log('data1', data1); 13 | return job2(); 14 | }) 15 | 16 | .then(function(data2) { 17 | console.log('data2', data2); 18 | return 'Hello world'; 19 | }) 20 | 21 | .then(function(data3) { 22 | console.log('data3', data3); 23 | }); 24 | 25 | function job1() { 26 | return new Promise(function(resolve, reject) { 27 | setTimeout(function() { 28 | resolve('result of job 1'); 29 | }, 1000); 30 | }); 31 | } 32 | 33 | function job2() { 34 | return new Promise(function(resolve, reject) { 35 | 36 | setTimeout(function() { 37 | resolve('result of job 2'); 38 | }, 1000); 39 | }); 40 | } 41 | ``` 42 | 43 | ## Async Await - ex 1 44 | ``` 45 | function job() { 46 | return new Promise(function(resolve, reject) { 47 | setTimeout(resolve, 500, 'Hello world 1'); 48 | }); 49 | } 50 | 51 | async function test() { 52 | let message = await job(); 53 | console.log(message); 54 | 55 | return 'Hello world 2'; 56 | } 57 | 58 | test().then(function(message) { 59 | console.log(message); 60 | }); 61 | ``` 62 | 63 | # Desafios 64 | 65 | ### Desafio 1 66 | O código abaixo está síncrono, você deve modificálo para que *callback1* seja chamado apenas uma vez depois de 2 segundos e *callback2* seja chamado 3 vezes com um intervalo de 1 segundo 67 | 68 | ``` 69 | function job(callback1, callback2) { 70 | callback1(); 71 | 72 | callback2(); 73 | callback2(); 74 | callback2(); 75 | } 76 | 77 | ``` 78 | 79 | [challenge](https://www.codingame.com/playgrounds/347/javascript-promises-mastering-the-asynchronous/some-pratice) 80 | 81 | ### Desafio 2 82 | 83 | Dado o código abaixo, a função job deve retornar um objeto de promise, a promise deve ser resolvida 2 segundos apóes invocar a função job e exibir um hello world 84 | 85 | ``` 86 | function job() { 87 | return 'hello world'; 88 | } 89 | 90 | ``` 91 | 92 | ### Desafio 3 93 | 94 | Nesse código, sua função recebe um parâmetro. Você deve modificar o código abaixo com base nas seguintes regras: 95 | 96 | * Sua função deve sempre retornar uma promise 97 | * Se os dados não forem um número, retorne uma promise rejeitada instantaneamente e mostre o conteúdo do "erro" 98 | * Se os dados forem um número ímpar, retorne uma promise resolvida 1 segundo depois e exiba a mensagem "ímpar" 99 | * Se os dados forem um número par, retorne uma promise rejeitada 2 segundos depois e exiba a mensagem "par" 100 | 101 | ``` 102 | function job(data) { 103 | return something; 104 | } 105 | ``` 106 | [challenge](https://www.codingame.com/playgrounds/347/javascript-promises-mastering-the-asynchronous/more-pratice-with-promises) 107 | 108 | ### Desafio 4 109 | 110 | O código a seguir usa promises para manipular um resultado assíncrono. O resultado é uma promise que gera um ID quando resolvido. Esse ID deve ser usado para recuperar informações do banco de dados. No final, sua função deve retornar a propriedade *name* da informação. Em caso de erro, você deve retornar uma promise rejeitada com o erro fornecido. Mas primeiro você deve notificar o errorManager com o erro. 111 | 112 | ``` 113 | function job(result, database, errorManager) { 114 | return result 115 | 116 | .then(function(id) { 117 | return database.get(id); 118 | }) 119 | 120 | .then(function(info) { 121 | return info.name; 122 | }) 123 | 124 | .catch(function(error) { 125 | errorManager.notify(error); 126 | throw error; 127 | }); 128 | } 129 | 130 | module.exports = job; 131 | ``` 132 | 133 | [challenge](https://www.codingame.com/playgrounds/482/javascript-async-and-await-keywords/time-to-pratice) 134 | -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/src/form/AddressForm.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Form, FormGroup, Label, Input, FormFeedback, Container, Row, Col, Button, Spinner } from 'reactstrap'; 3 | 4 | class AddressForm extends React.Component{ 5 | constructor(props){ 6 | super(props) 7 | this.state ={ 8 | cep: '', 9 | bairro: '', 10 | logradouro: '', 11 | localidade: '', 12 | uf: '', 13 | numero: '', 14 | loading:false, 15 | error: '' 16 | } 17 | } 18 | 19 | verificaCep = async (cep) => { 20 | console.log("VERIFICA", cep) 21 | this.setState({error:false}) 22 | return await fetch(`http://viacep.com.br/ws/${cep}/json/`) 23 | .then(res => res.json()) 24 | .then(cepResult => { 25 | this.setState({loading:false}) 26 | return cepResult 27 | }) 28 | .catch(error => this.setState({error:true, loading:false})) 29 | } 30 | 31 | handleChange = async (field) => { 32 | const { name, value } = field 33 | this.setState({[name]: value, error:false}) 34 | if(name === 'cep' && value.length ===8 ){ 35 | this.setState({loading:true}) 36 | const cepObject = await this.verificaCep(value) 37 | if(cepObject.erro){ 38 | this.setState({error:true}) 39 | return 40 | } 41 | console.log("CEPOBJ", cepObject) 42 | const { cep, logradouro, bairro, localidade, uf } = cepObject 43 | this.setState({cep, logradouro, bairro, localidade, uf}) 44 | } 45 | } 46 | 47 | handleBlur = async value => { 48 | if(value.length === 8 ){ 49 | this.setState({loading:true}) 50 | const cepObject = await this.verificaCep(value) 51 | if(cepObject.erro){ 52 | this.setState({error:true}) 53 | return 54 | } 55 | const { cep, logradouro, bairro, localidade, uf } = cepObject 56 | this.setState({cep, logradouro, bairro, localidade, uf}) 57 | } 58 | } 59 | 60 | render() { 61 | const { loading, cep, logradouro, bairro, localidade, uf, numero, error } = this.state 62 | return( 63 | 64 | 65 | 66 | {loading && } 67 |
68 | 69 | 70 | this.handleChange(e.target)} onBlur={e => this.handleBlur(e.target.value)} maxLength={9}/> 71 | Error 72 | 73 | 74 | 75 | this.handleChange(e.target)}/> 76 | 77 | 78 | 79 | this.handleChange(e.target)}/> 80 | 81 | 82 | 83 | this.handleChange(e.target)}/> 84 | 85 | 86 | 87 | this.handleChange(e.target)}/> 88 | 89 | 90 | 91 | this.handleChange(e.target)}/> 92 | 93 | 94 | 95 | 96 |
97 | 98 |
99 |
100 | ) 101 | } 102 | } 103 | 104 | export default AddressForm -------------------------------------------------------------------------------- /aula-3-lets-input-react/live/cep-api/src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.0/8 are considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl, { 104 | headers: { 'Service-Worker': 'script' } 105 | }) 106 | .then(response => { 107 | // Ensure service worker exists, and that we really are getting a JS file. 108 | const contentType = response.headers.get('content-type'); 109 | if ( 110 | response.status === 404 || 111 | (contentType != null && contentType.indexOf('javascript') === -1) 112 | ) { 113 | // No service worker found. Probably a different app. Reload the page. 114 | navigator.serviceWorker.ready.then(registration => { 115 | registration.unregister().then(() => { 116 | window.location.reload(); 117 | }); 118 | }); 119 | } else { 120 | // Service worker found. Proceed as normal. 121 | registerValidSW(swUrl, config); 122 | } 123 | }) 124 | .catch(() => { 125 | console.log( 126 | 'No internet connection found. App is running in offline mode.' 127 | ); 128 | }); 129 | } 130 | 131 | export function unregister() { 132 | if ('serviceWorker' in navigator) { 133 | navigator.serviceWorker.ready 134 | .then(registration => { 135 | registration.unregister(); 136 | }) 137 | .catch(error => { 138 | console.error(error.message); 139 | }); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /aula-5-lets-hooks-it-all/live/redux-hooks-demo/src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.0/8 are considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl, { 104 | headers: { 'Service-Worker': 'script' } 105 | }) 106 | .then(response => { 107 | // Ensure service worker exists, and that we really are getting a JS file. 108 | const contentType = response.headers.get('content-type'); 109 | if ( 110 | response.status === 404 || 111 | (contentType != null && contentType.indexOf('javascript') === -1) 112 | ) { 113 | // No service worker found. Probably a different app. Reload the page. 114 | navigator.serviceWorker.ready.then(registration => { 115 | registration.unregister().then(() => { 116 | window.location.reload(); 117 | }); 118 | }); 119 | } else { 120 | // Service worker found. Proceed as normal. 121 | registerValidSW(swUrl, config); 122 | } 123 | }) 124 | .catch(() => { 125 | console.log( 126 | 'No internet connection found. App is running in offline mode.' 127 | ); 128 | }); 129 | } 130 | 131 | export function unregister() { 132 | if ('serviceWorker' in navigator) { 133 | navigator.serviceWorker.ready 134 | .then(registration => { 135 | registration.unregister(); 136 | }) 137 | .catch(error => { 138 | console.error(error.message); 139 | }); 140 | } 141 | } 142 | --------------------------------------------------------------------------------