Last active
June 29, 2022 08:32
-
-
Save avcs06/e97ba78bf499c7cfc1bc5b93283656c6 to your computer and use it in GitHub Desktop.
Convert prop to state, with ability to change it locally
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from 'react'; | |
import useLazyEffect from './useLazyEffect'; | |
const usePropState = (prop) => { | |
const [value, setValue] = useState(prop); | |
useLazyEffect(() => { | |
setValue(prop); | |
}, [prop]); | |
return [value, setValue]; | |
}; | |
export default usePropState; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment