Skip to content

Instantly share code, notes, and snippets.

View evertonstrack's full-sized avatar
🚀

Everton Strack evertonstrack

🚀
View GitHub Profile
@evertonstrack
evertonstrack / service-wroker.js
Created July 31, 2018 22:14
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',
import React, { Component } from 'react';
export default class UserData extends Component {
constructor(){
super();
this.state = {
name: ''
};
}
// 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
@evertonstrack
evertonstrack / useInput.hook.js
Last active April 23, 2019 13:28
useInput.hook.js
export function useInput(initialValue = '') {
const [value, setValue] = useState(initialValue);
const onChange = e => setValue(e.target.value);
return { onChange, value }
}
@evertonstrack
evertonstrack / readTxtFile.js
Created April 25, 2019 19:26
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);
});
}