move to Donetick Org, First commit frontend
This commit is contained in:
commit
2657469964
105 changed files with 21572 additions and 0 deletions
16
src/hooks/useStickyState.js
Normal file
16
src/hooks/useStickyState.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { useEffect, useState } from 'react'
|
||||
|
||||
const useStickyState = (defaultValue, key) => {
|
||||
const [value, setValue] = useState(() => {
|
||||
const stickyValue = window.localStorage.getItem(key)
|
||||
return stickyValue !== null ? JSON.parse(stickyValue) : defaultValue
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
window.localStorage.setItem(key, JSON.stringify(value))
|
||||
}, [key, value])
|
||||
|
||||
return [value, setValue]
|
||||
}
|
||||
|
||||
export default useStickyState
|
Loading…
Add table
Add a link
Reference in a new issue