import { useState,useEffect } from 'react';
export function useGetStorage (key,value){
const [data,setData] = useState(value)
useEffect(()=>{
window.localStorage.setItem(key,data)
},[data,key])
return [data,setData]
}
import{useGetStorage} from './getlocalstorage'
function App(){
const [a,b] =useGetStorage('這是key','我愛你')
setTimeout(() => {
b('yes')
}, 2000);
return(
<div style={{height:'5000px'}}>
<p style={{position:'fixed',top:`100px`}}>
{a}
</p>
</div>
)
}
export default App