Skip to content

Instantly share code, notes, and snippets.

View anderjs's full-sized avatar
:electron:
Learn never exhaust the mind

Anderson anderjs

:electron:
Learn never exhaust the mind
View GitHub Profile
@anderjs
anderjs / index.js
Last active January 20, 2020 18:26
import React, { memo, useEffect, useRef, useState } from 'react'
import Icon from 'react-icons-kit'
import { Button } from 'react-bootstrap'
import { ic_play_arrow } from 'react-icons-kit/md/ic_play_arrow'
import { ic_pause } from 'react-icons-kit/md/ic_pause'
import { ToastsStore } from 'react-toasts'
import FlexContainer from './FlexContainer'
import Stopwatch from './Stopwatch'
import Emoji from './Emoji'
// Para guardar datos necesitas una llave o un nombre para asignarlo en el localStorage
// Guardar datos
localStorage.setItem('DATOS', JSON.stringify({ nombre: "Anderson", apellido: "Arevalo" }))
// El primer argumento guarda la referencia del key, en este caso "DATOS" es nuestro objeto
// Para obtener usamos los siguiente
import { useState, useCallback, useMemo } from 'react'
/**
*
* @param {number} initialValue
* @param {number} limit
*/
function useCounter(initialValue, limit) {
const [ state, setState ] = useState({
value: initialValue,
import { useMemo } from 'react'
const Component = () => {
const getColor = useMemo(() => {
const colors = ['danger', 'warning', 'secondary]
return colors.find((_color, index) => index === step)
}, [step])
import React, { memo } from 'react'
import PropTypes from 'prop-types'
import Happy from '../../assets/img/happy.png'
const Emoji = ({ type }) => {
const icons = new Map([
['happy', { src: Image, width: 300, height: 300, className: '' }],
['sad', { src: '', width: 0, height: 300, className: '']
])
import { Router } from 'express'
import fs from 'fs'
import multer, { diskStorage } from 'multer'
import path from 'path'
/**
* @description
* Allows to control all malicious content via FormData.
* @param {{}} file
* @param {function} callback
const DepartmentButton = ({ onMouseOver }) => {
<button onMouseOver={onMouseOver}>Example</button>
}
const App = () => {
const [classList, setClassList] = useState('inactive')
function onMouseOverHandler() {
if (!isMobileDevice()) {
setClassList('activo')
}
import React from 'react'
const SwitchButton = () => {
const [state, setState] = React.useState(false)
function onClickSwitchButton() {
setState(state => !state)
}
return (
@anderjs
anderjs / Example.js
Last active August 21, 2019 23:01
Pass a prop
import React from 'react'
const ChildComponent = ({ onPress }) => (
<button onClick={() => onPress('Hola mundo!')}>Click me</button>
);
// Parent
const ParentComponent = () => {
const [state, setState] = React.useState(false)
@anderjs
anderjs / clone.js
Created August 8, 2019 21:50
A deep cloning using JavaScript.
const { keys } = Object
const { isArray } = Array
/**
* @param {any} fragment
*/
function applyCloningElement(fragment) {
if (typeof fragment !== 'object') {
return fragment
}