Skip to content

Instantly share code, notes, and snippets.

View matiasfha's full-sized avatar

Matías Hernández Arellano matiasfha

View GitHub Profile
@matiasfha
matiasfha / createSharingImage.js
Last active May 3, 2022 22:19
createSharingImage utility function using cloudinary transformations
const createSharingImage = ({ cloudName, text }) => {
const imageTransformations = [
'w_1200',
'h_627',
'c_fill',
'q_auto',
'f_auto'
].join(',')
const textTransformations = [
'w_600',
const DummyComp = ({datos}) =>{
return <ul>
{datos.map((campeon)=>(
<li>{campeon.name}</li>
))}
</ul>
}
@matiasfha
matiasfha / basic-hooks.js
Created September 30, 2020 17:50
useState, useEffect, fetch ejemplo
const DummyComponent = () => {
const [ data, setData ] = React.useState([]) // data inicialmente será un arreglo vacio
React.useEffect(() => {
const requestData = async () => {
const respone = await fetch('http://someurl/request.json')
const json = await response.json()
setData(json.data) // Aquí se actualiza el estado con un nuevo arreglo que proviene desde el response
}
}, []) // Ya que no hay dependencias este arreglo va vacío y el efecto se ejecutará sólo una vez.
@matiasfha
matiasfha / test.js
Last active August 5, 2020 14:38
Context issue
import React from 'react';
const CompContext = React.createContext()
const reducer = (state, action) => {
switch(action.type){
case 'ADD_CHILD':
return {...state, total: state.total + 1 }
case 'SOME_OTHER_TYPE':
return {...state, otherState: `use ${state.total} to do some calc`}
@matiasfha
matiasfha / ObjectspreadExample.js
Created June 11, 2020 10:52
Utilizar Object spread para asegurar inmutabilidad
// Forma original Object.assign
const originalState = { foo: 'foo' }
const newState = Object.assign({}, originalState, {
visibilityFilter: action.filter
})
//Forma con Spread
const newState = return { ...originalState, visibilityFilter: action.filter }
@matiasfha
matiasfha / eslint-plugin-rule-example.js
Created May 27, 2020 15:53
A example rule for a basic eslint plugin
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "Force Async function naming convention",
category: "Possible Errors",
recommended: true,
},
},
create: function (context) {
@matiasfha
matiasfha / README.md
Created November 7, 2019 04:08
Honesto README

Based on the description of the application, the proposed design and the questions made during the call with the client, the plan was to work 4 hours daily and focusing on different areas to try to accomplish the implementation of the main functionality and main UI/UX. The proposed plan was the following:

the job should be complete by Monday 4 at night (CLST time).
The main functionality that will be implemented is:

- [x] Landing/Login screen without authentication functionality
  • Feedback landing page/tab with mock users data
@matiasfha
matiasfha / flatten.js
Created October 7, 2019 17:54
Array flatten for es6
/* This function use array.reduce
* https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Array/reduce
* to recursively flatten a multidemensional array.
* The array can be arbitrarly deep
*/
const flatten = list => list.reduce(
(a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
);
// Testing with chai and mocha
{
"errors": [
{
"message": "Invalid UserPoolId format.",
"locations": [
{
"line": 2,
"column": 3
}
],
@matiasfha
matiasfha / profiler.js
Created June 11, 2018 12:37
Profile Component
const Profiler = React.unstable_Profiler;
render(
{/* Components not measured... */}
<Profiler id="some identifier" onRender={loggingFunction}>
{/* Components to be measured... */}
</Profiler>
{/* Components not measured... */}
);