mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
refactor: memoize useStateIO
This commit is contained in:
parent
c492397a34
commit
a01a7ede9e
1 changed files with 2 additions and 4 deletions
|
|
@ -1,11 +1,9 @@
|
|||
import * as React from 'react'
|
||||
|
||||
export function useStateIO<S>(
|
||||
initialState: S | (() => S),
|
||||
): {
|
||||
export function useStateIO<S>(initialState: S | (() => S)): {
|
||||
value: S
|
||||
onChange: React.Dispatch<React.SetStateAction<S>>
|
||||
} {
|
||||
const [value, onChange] = React.useState(initialState)
|
||||
return { value, onChange }
|
||||
return React.useMemo(() => ({ value, onChange }), [value])
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue