Skip to content

Instantly share code, notes, and snippets.

View doug2k1's full-sized avatar

Douglas Matoso doug2k1

  • Campinas - SP - Brazil
View GitHub Profile
// requisição:
// adicionar um novo endereço de e-mail à minha conta do GitHub
fetch('https://api.github.com/user/emails', { // URI
method: 'POST', // método
body: JSON.stringify(["[email protected]"]) // corpo
})
.then(response => {
// recebemos a resposta e logamos o status
console.log(response.status)
// retorna o corpo em formato JSON
// requisição:
// não é preciso informar o método (GET é o padrão),
// nem cabeçalho ou corpo (requisição GET não precisa de corpo)
fetch('https://api.github.com/repos/facebook/react/releases/latest') // URI
.then(response => {
// recebemos a resposta e logamos o status
console.log(response.status)
// retorna o corpo da resposta em formato JSON
return response.json()
})
// the request:
// try to GET an nonexistent URI
fetch('https://api.github.com/nonexistent-uri')
.then(response => {
if (response.ok) {
// we should not reach here
console.log('success')
} else {
console.log(response.status)
}
// the request:
// POST a new email address to my GitHub account
fetch('https://api.github.com/user/emails', { // the URI
method: 'POST', // the method
body: JSON.stringify(["[email protected]"]) // the body
})
.then(response => {
// we received the response and print the status code
console.log(response.status)
// return response body as JSON
// the request:
// GET information about the latest React release on GitHub
// we don't need to inform the method (GET is the default),
// headers or body (GET request doesn't need one)
fetch('https://api.github.com/repos/facebook/react/releases/latest') // the URI
.then(response => {
// we received the response and print the status code
console.log(response.status)
// return response body as JSON
return response.json()
const path = require('path')
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve('dist'),
filename: 'bundle.js'
},
import React from 'react'
import './icons.svg'
const Icon = (props) => (
<svg className={`icon icon-${props.name}`}>
<use xlinkHref={`#icons_${props.name}`} />
</svg>
)
export default Icon
// criar uma função que recebe uma lista de alunos
// e loga (console.log) se o aluno foi aprovado,
// ou o motivo da reprovação. Ex:
// Fulano foi aprovado(a)
// Fulano foi reprovado(a) por nota
// Fulano foi reprovado(a) por faltas
// OBS.: Critérios de aprovação: nota maior ou igual a 6 e
// faltas menor que 25% do total de aulas
var totalAulas = 30;
class UserListContainer extends React.Component {
...
toggleActive (event) {
// event logic
}
render () {
return (
<UserList users={this.state.users} toggleActive={this.toggleActive} />
const UserList = (props) => {
return (
<ul>
{props.users.map(user => <li key={user.id}>{user.name}</li>)}
</ul>
);
};