This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect, useRef, useState } from 'react' | |
| // The callback should setState so it will re trigger the timeout | |
| function useTimeout(callback, delay) { | |
| const savedCallback = useRef() | |
| const [callBackCleanUp, setCallBackCleanUp] = useState(null) | |
| // Remember the latest callback. | |
| useEffect(() => { | |
| savedCallback.current = callback | |
| }, [callback]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .li { | |
| max-height: 0px; | |
| transition: max-height 0.35s ease-out; | |
| } | |
| .ul { | |
| overflow: hidden; | |
| } | |
| .ul.opened .li { | |
| max-height: 50px; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
NewerOlder