⬆️ and ⬇️
- i- in
- o - out
import React, { useEffect } from 'react'; | |
import { useExampleContext, actions, ExampleProvider } from 'context/ExampleContext'; | |
const Page = () => { | |
// first element is the state | |
// second is the actions dispatcher | |
const [{ greet }, dispatch] = useExampleContext(); | |
useEffect(() => { | |
dispatch({ | |
type: actions.GREET_UPDATE, |
// ITERATORS | |
// Exemplo de modificar o iterator para adicionar uma string 'is Sexy' | |
// sempre que utilizamos um for of loop | |
let myArray = ['Antonio', 'Toze', 'Toninho']; | |
myArray[Symbol.iterator] = function() { | |
let index = -1; | |
const length = this.length; | |
const arr = this; |
// default state | |
const defaultState = { | |
welcome: 'Hello', | |
otherState: 'some stuff', | |
} | |
// reducer, always returns new object based on the action type | |
const greeting = (state = defaultState, action) => { | |
switch (action.type) { | |
case 'GREET_ME': |
const axios = require('axios'); | |
const getExchangeRate = async (from, to) => { | |
try { | |
const response = await axios.get('http://data.fixer.io/api/latest?access_key=d32d75de5146611ae7f23de0782ac09b'); | |
const euro = 1 / response.data.rates[from]; | |
const rate = euro * response.data.rates[to]; | |
if (isNaN(rate)) { | |
throw new Error(); |
<template> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-xs-12 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3"> | |
<h1>Animations</h1> | |
<hr> | |
<button class="btn btn-primary" @click="show=!show">Show alert</button> | |
<br><br> | |
<transition name="fade"> | |
<div class="alert alert-info" v-if="show">This is some info</div> |
{ | |
"eslint.validate": [ | |
"javascript", | |
"javascriptreact", | |
"vue" | |
], | |
"editor.fontFamily": "Consolas , Menlo, Monaco, 'Courier New', monospace, 'Apple Color Emoji'", | |
"editor.fontSize": 14, | |
"terminal.integrated.shell.osx": "zsh", | |
"[markdown]": { |