refactor hooks

This commit is contained in:
Pig Fang 2020-04-30 22:57:57 +08:00
parent 80d67c4518
commit 6e82468692
2 changed files with 5 additions and 10 deletions

View File

@ -4,10 +4,7 @@ import { Texture, TextureType } from '../types'
type Response = fetch.ResponseBody<Texture> type Response = fetch.ResponseBody<Texture>
export default function useTexture(): [ export default function useTexture() {
{ url: string; type: TextureType },
React.Dispatch<React.SetStateAction<number>>,
] {
const [tid, setTid] = useState(0) const [tid, setTid] = useState(0)
const [url, setUrl] = useState('') const [url, setUrl] = useState('')
const [type, setType] = useState<TextureType>('steve') const [type, setType] = useState<TextureType>('steve')
@ -29,5 +26,5 @@ export default function useTexture(): [
getTexture() getTexture()
}, [tid]) }, [tid])
return [{ url, type }, setTid] return [{ url, type }, setTid] as const
} }

View File

@ -1,9 +1,7 @@
import React, { useState, useEffect, useRef } from 'react' import { useState, useEffect, useRef } from 'react'
import TWEEN from '@tweenjs/tween.js' import TWEEN from '@tweenjs/tween.js'
export default function useTween<T = any>( export default function useTween<T = any>(initialValue: T) {
initialValue: T,
): [T, React.Dispatch<React.SetStateAction<T>>] {
const [value, setValue] = useState<T>(initialValue) const [value, setValue] = useState<T>(initialValue)
const ref = useRef<T>(value) const ref = useRef<T>(value)
const [dest, setDest] = useState<T>(initialValue) const [dest, setDest] = useState<T>(initialValue)
@ -20,5 +18,5 @@ export default function useTween<T = any>(
animate() animate()
}, [dest]) }, [dest])
return [value, setDest] return [value, setDest] as const
} }