Skip to content

Instantly share code, notes, and snippets.

View viniciusdacal's full-sized avatar

Vinicius Dacal viniciusdacal

View GitHub Profile
import React, { useState, useContext } from 'react';
import { useHistory, useLocation } from 'react-router-dom';
import StoreContext from 'components/Store/Context';
import UIButton from 'components/UI/Button/Button';
import './Login.css';
function initialState() {
return { user: '', password: '' };
}
import React, { useContext } from 'react';
import { Route, Redirect } from 'react-router-dom';
import StoreContext from 'components/Store/Context';
const RoutesPrivate = ({ component: Component, ...rest}) => {
const { token } = useContext(StoreContext);
return (
<Route
{
"promotions": [
{
"id": 1,
"title": "Kit Notebook Acer Aspire 3 + Mochila Green, A315-41-R790, AMD Ryzen 3 2200U Dual Core",
"price": 1799,
"imageUrl": "https://cdn.gatry.com/gatry-static/promocao/imagem_url/2631517face1861bc4f46ae154d387de.png"
},
{
"id": 2,
import { useState } from 'react';
import axios from 'axios';
const api = axios.create({
baseURL: '/api'
});
const initialState = { pending: true, error: null, data: null };
export default function useLazyRest(options = {}) {
const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('db.json');
const middlewares = jsonServer.defaults();
server.use(middlewares);
server.use(jsonServer.bodyParser);
router.render = (req, res) => {
if (req.method === 'GET') {
const paths = req._parsedUrl.pathname.split('/').filter(path => Boolean(path));
let ajaxCalls = async () => {
const r1 = await someajaxPromiseFn1();
const r2 = await someajaxPromiseFn2(r1);
const r3 = await someajaxPromiseFn3(r2);
setState();
}
{
"id": 1,
"title": "Kit Notebook Acer Aspire 3 + Mochila Green, A315-41-R790, AMD Ryzen 3 2200U Dual Core",
"price": 1799,
"imageUrl": "https://cdn.gatry.com/gatry-static/promocao/imagem_url/2631517face1861bc4f46ae154d387de.png",
"url": "https://www.amazon.com.br/Notebook-Acer-Mochila-A315-41-R790-Mem%C3%B3ria/dp/B07YDWLV7S/ref=as_li_ss_tl?ie=UTF8&linkCode=sl1&tag=gatry0b-20&linkId=e4a1146599e36741a720a6a952cbc328&language=pt_BR",
"comments": [
{
"id": 1,
"comment": "TELA HD"
//callback
function listarProdutos(data) {
console.log(data.produtos);
}
//callback
function removerProduto() {
console.log('remover produto da tela');
}
@viniciusdacal
viniciusdacal / windowopen.js
Created October 23, 2018 18:14
windowopen
const credentials = {
};
function setCredentials(user) {
credentials.user = user;
}
//to actually open the window..
var win = window.open("window.html");
win.onload = function() { win.callback = setCredentials; };
import React from 'react';
import UserForm from '../../components/User/Form/Form';
const ScreensUserForm = ({ match: { params } }) => (
<div>
<h1>
{`${!params.id ? 'Create' : 'Update'}`} User
</h1>
<UserForm id={params.id} />
</div>