- A React component can only return one parent element.
return <h1>Hello</h1><p>World</p> // error
return <div><h1>Hello</h1><p>World</p></div> // okay - JavaScript expressions can be interpolated in JSX with
{}
| /** | |
| * Filters an array of objects using custom predicates. | |
| * | |
| * @param {Array} array: the array to filter | |
| * @param {Object} filters: an object with the filter criteria | |
| * @return {Array} | |
| */ | |
| function filterArray(array, filters) { | |
| const filterKeys = Object.keys(filters); | |
| return array.filter(item => { |
| lista = [1, 10] | |
| try: | |
| divisao = 10 / 1 | |
| numero = lista[1 | |
| x = a | |
| except ZeroDivisionError # classe de excessões acoplada ja no python | |
| print('Não é possivel realizar uma divisão por 0') | |
| except IndexError: | |
| print('Erro ao acessar um indice inválido da lista') |
| from datetime import date, time, datetime | |
| def trabalhando_com_datetime(): | |
| data_atual = datetime.now() | |
| data_atual_formatada = data_atual.strftime('%d/%m/%Y %H:%M:%S') | |
| print(data_atual.minute) | |
| print(data_atual.weekday()) | |
| tupla = ('Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sabado', 'Domingo') | |
| print(tupla[data_atual.weekday()]) | |
| data_criada = datetime(2020, 6, 22, 15, 30, 20) |
| import shutil | |
| def escrever_arquivo(texto): | |
| arquivo = open('contatos.txt', 'w') | |
| arquivo.write(texto) | |
| arquivo.close() | |
| def atualizar_arquivo(nome_arquivo, texto): | |
| arquivo = open(nome_arquivo, 'a') | |
| arquivo.write(texto) |
| calculadora = { | |
| 'soma': lambda a, b: a + b, | |
| 'subtracao': lambda a, b: a - b, | |
| 'multiplicacao': lambda a, b: a * b, | |
| 'divisao': lambda a, b: a / b | |
| } | |
| soma = calculadora['soma'] | |
| print('A soma é: {}'.format(soma(10, 5))) |
| function composicao(...funcoes) { | |
| return function(valor) { | |
| return funcoes.reduce((acc, fn) => { | |
| return fn(acc) | |
| }, valor) | |
| } | |
| } |
| const exampleArray = [ [ [ 'value' ] ] ] | |
| // bad | |
| exampleArray.forEach((array1) => { | |
| array1.forEach((array2) => { | |
| array2.forEach((el) => { | |
| console.log(el) | |
| }) | |
| }) | |
| }) |
| import axios from 'axios'; | |
| class Api { | |
| static async getUserInfo(username) { | |
| try { | |
| const response = await axios.get(`https://api.github.com/users/${username}`); | |
| console.log(response); | |
| } catch { | |
| console.warn('erro na api'); | |
| } |
| { | |
| "presets": ["@babel/preset-env"], | |
| "plugins": [ | |
| "@babel/plugin-proposal-object-rest-spread", | |
| "@babel/plugin-transform-async-to-generator" | |
| ] | |
| } |