Skip to content

Instantly share code, notes, and snippets.

View EduVencovsky's full-sized avatar
🎯
Focusing

Eduardo Vencovsky EduVencovsky

🎯
Focusing
View GitHub Profile
@EduVencovsky
EduVencovsky / useDimensions.js
Created July 13, 2019 13:56
React Native Hook for Dimensions
import { useState, useEffect } from 'react'
import { Dimensions } from 'react-native'
const useDimensions = getter => {
const [dimensions, setDimensions] = useState(Dimensions.get(getter))
useEffect(() => {
const widthHandler = d => setDimensions(d[getter])
Dimensions.addEventListener('change', widthHandler)
return () => Dimensions.removeEventListener('change', widthHandler)
})
@EduVencovsky
EduVencovsky / styles.css
Created May 22, 2019 15:41
CSS for making ul and li open and close (dropdown menu)
.li {
max-height: 0px;
transition: max-height 0.35s ease-out;
}
.ul {
overflow: hidden;
}
.ul.opened .li {
max-height: 50px;
@EduVencovsky
EduVencovsky / Auth.jsx
Last active February 20, 2024 03:28
Private Routes with Auth using react-router and Context API
import React, { useState, useEffect } from 'react'
import PropTypes from 'prop-types'
import { checkIsAuthenticated, authSignUp, authLogin, authLogout } from '../../services/auth'
export const AuthContext = React.createContext({})
export default function Auth({ children }) {
const [isAuthenticated, setIsAuthenticated] = useState(false)
const [isLoading, setIsLoading] = useState(true)
@EduVencovsky
EduVencovsky / useInterval.js
Last active July 13, 2019 14:22
React Hook for using setInterval
// https://overreacted.io/making-setinterval-declarative-with-react-hooks/
import { useEffect, useRef } from 'react'
function useInterval(callback, delay) {
const savedCallback = useRef()
// Remember the latest callback.
useEffect(() => {
savedCallback.current = callback
}, [callback])
@EduVencovsky
EduVencovsky / storage.js
Last active March 28, 2019 19:58
React Native AsyncStorage Implementation
import { AsyncStorage } from 'react-native' // change this to @react-native-community/async-storage when this issue is solved https://github.com/react-native-community/react-native-async-storage/issues/14
export default Storage = {
async getItem(itemKey) {
let result = {
key: itemKey,
value: null,
error: null,
}
@EduVencovsky
EduVencovsky / useArray.js
Last active April 18, 2019 15:23
React Hook for using arrays
import { useReducer } from 'react'
function arrayReducer(array, action) {
switch (action.type) {
case 'push':
return [...array, action.value]
case 'pushAll':
return [...array, ...action.value]
case 'deleteByIndex':
let deleteByIndex = array.filter((x, i) => i != action.index)