Skip to content

Instantly share code, notes, and snippets.

@avcs06
Last active June 29, 2022 08:32
Show Gist options
  • Save avcs06/e97ba78bf499c7cfc1bc5b93283656c6 to your computer and use it in GitHub Desktop.
Save avcs06/e97ba78bf499c7cfc1bc5b93283656c6 to your computer and use it in GitHub Desktop.
Convert prop to state, with ability to change it locally
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