Skip to content

Instantly share code, notes, and snippets.

View matheusrod92's full-sized avatar
🏠
Working from home

Matheus Rodrigues matheusrod92

🏠
Working from home
  • Ring
  • São Paulo, São Paulo, Brasil
View GitHub Profile
@matheusrod92
matheusrod92 / index.js
Last active October 17, 2019 16:53
Messages with links using react-intl
import React from 'react'
import { FormattedMessage } from 'react-intl'
import messages from './messages'
// it can be a component or a variable
const Link = () => (
<a nohref rel="noopener noreferrer">
<FormattedMessage {...messages.reminderLink} />
</a>
@matheusrod92
matheusrod92 / action-example.js
Created August 12, 2019 18:55
Amplitude Redux Middleware
const myHypotheticalAction = (data) => ({
type: 'MY_HYPOTHETICAL_ACTION',
amplitude: {
event: {
name: 'my-hypothetical-amplitude-event',
properties: data,
},
identify: true,
},
});
@matheusrod92
matheusrod92 / App.js
Created April 5, 2019 03:53
React API Middleware to inject API Methods and State into component/container
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import rickAndMortyApi from './apis/rickAndMorty';
import withApi from './middlewares/withApi';
class App extends PureComponent {
handleMorty = () => {
const { getMorty } = this.props;
getMorty();
@matheusrod92
matheusrod92 / update-parent-state-react.js
Created November 20, 2018 18:14
Como atualizar estado de um componente pai em react
import React from 'react';
import PropTypes from 'prop-types';
const Filho = (props) => (
<div>
<b>Eu sou um componente stateless</b>
<span> mas eu controlo o state do meu pai!</span>
<input
type="text"
value={props.valorDoPapaizineo}
function getIp() {
//inicializo a classe de requisições
const xhr = new XMLHttpRequest();
//defino o metodo a ser utilizado (get/post/put/patch/delete)
const method = 'GET';
//defino a url que sera utilizada na minah requisição
const url = 'https://ipapi.co/json/';
//inicializo a requisição passando o metodo e a url e afirmo que minha requisição sera SINCRONA utilizando o false
xhr.open(method, url, false)
//executo a requisição configurada acima