This file contains 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 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) |
This file contains 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 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 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 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 Realm from '../database/migrations' | |
function reducer(action, { realm, name, queryObjects }) { | |
switch (action.type) { | |
case 'create': | |
return new Promise((resolve, reject) => { | |
try { | |
realm.write(() => { | |
resolve(realm.create(name, action.data)) |
This file contains 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 } from 'react' | |
export default function useToggle(defaultValue){ | |
const [state, setState] = useState(defaultValue) | |
const toggle = (value = null) => { | |
if(value == null) | |
setState(!state) | |
else | |
setState(!!value) |
This file contains 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
<button id="open">open</button> | |
<div class="box scale"> | |
<h1> | |
hey | |
</h1> | |
</div> |
This file contains 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, { 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 |
OlderNewer