Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀

Everton Strack evertonstrack

🚀
View GitHub Profile
View readTxtFile.js
function readTxtFile(event) {
return new Promise((resolve, reject) => {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.readAsText(file);
});
}
View useInput.hook.js
export function useInput(initialValue = '') {
const [value, setValue] = useState(initialValue);
const onChange = e => setValue(e.target.value);
return { onChange, value }
}
View service-worker.js
// Reponde o request direto do cache
this.addEventListener("fetch", event => {
event.respondWith(
caches.match(event.request)
.then(response => {
// Retorna o cache
if (response) {
return response;
}
// Faz a requisição
View Component.js
import React, { Component } from 'react';
export default class UserData extends Component {
constructor(){
super();
this.state = {
name: ''
};
}
View service-wroker.js
// Criando um nome para o arquivo de cache
const staticCache = "meu-site-2018-07-31-21-13";
// Lista de arquivos que devem ser cacheados
const files = [
'/',
'/sobre',
'/contato',
'/images/logo.jpg',
'/assets/styles/main.min.css',