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>
export default function useTexture(): [
{ url: string; type: TextureType },
React.Dispatch<React.SetStateAction<number>>,
] {
export default function useTexture() {
const [tid, setTid] = useState(0)
const [url, setUrl] = useState('')
const [type, setType] = useState<TextureType>('steve')
@ -29,5 +26,5 @@ export default function useTexture(): [
getTexture()
}, [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'
export default function useTween<T = any>(
initialValue: T,
): [T, React.Dispatch<React.SetStateAction<T>>] {
export default function useTween<T = any>(initialValue: T) {
const [value, setValue] = useState<T>(initialValue)
const ref = useRef<T>(value)
const [dest, setDest] = useState<T>(initialValue)
@ -20,5 +18,5 @@ export default function useTween<T = any>(
animate()
}, [dest])
return [value, setDest]
return [value, setDest] as const
}