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 / 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 / useAsyncStorage.js
Last active April 27, 2022 07:33
React Native hook for keeping the state in sync with AsyncStorage
import { useState, useEffect } from 'react'
import AsyncStorage from '@react-native-community/async-storage'
const useAsyncStorage = (key, initialValue) => {
const [hasLoad, setHasLoad] = useState(false)
const [data, setData] = useState(initialValue)
const set = async newData => {
setData(newData)
return newData === null ?
@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 / CustomAttributeHelper.cs
Last active June 17, 2021 08:01
Helper to get custom attributes from a property with Blazor
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace ADD_YOUR_NAME_SPACE_HERE
{
public static class CustomAttributeHelper
{
public static MemberInfo GetExpressionMember<T>(Expression<Func<T>> accessor)
@EduVencovsky
EduVencovsky / TodoList.tsx
Created August 1, 2020 14:11
Todo List com React Hooks, Typescript e Material-UI
import React, { useState } from 'react'
import { TextField, IconButton } from '@material-ui/core'
import AddIcon from '@material-ui/icons/Add'
import DeleteIcon from '@material-ui/icons/Delete'
interface TodoItem {
id: number
value: string
}
@EduVencovsky
EduVencovsky / ga.ipynb
Last active April 19, 2020 19:47
Use um AG para encontrar o ponto máximo da função: f(x) = x^2 sendo 0 <= x <= 31 e x é inteiro
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@EduVencovsky
EduVencovsky / RotateView.js
Created November 13, 2019 01:15
Component for creating a rotating View in React Native
import React, { useEffect, useState } from 'react'
import PropTypes from 'prop-types'
import { Animated, Easing } from 'react-native'
const RotateView = ({ rotate, degree, initialDegree, duration, children, ...otherProps }) => {
const [rotateValue] = useState(new Animated.Value(0))
useEffect(() => {
const toValue = rotate ? 1 : 0
@EduVencovsky
EduVencovsky / useNavigationFocusChanged.js
Last active November 8, 2019 01:08
React Hooks to listen to navigation didFocus event
import { useState, useEffect, useRef } from 'react'
export const useNavigationFocusChanged = (navigation, event) => {
const [focus, setFocus] = useState(false)
const listener = useRef(null)
useEffect(() => {
const changeFocus = () => {
setFocus(prev => !prev)
}
listener.current = navigation.addListener(event, changeFocus)
@EduVencovsky
EduVencovsky / index.html
Created October 22, 2019 18:52
CSS Scale Transition
<button id="open">open</button>
<div class="box scale">
<h1>
hey
</h1>
</div>
import { useState } from 'react'
export default function useToggle(defaultValue){
const [state, setState] = useState(defaultValue)
const toggle = (value = null) => {
if(value == null)
setState(!state)
else
setState(!!value)