mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
14 lines
323 B
TypeScript
14 lines
323 B
TypeScript
import { useState } from 'react';
|
|
|
|
const useDefault = (defaultValue, initialValue): [any, (nextValue?: any) => void] => {
|
|
const [value, setValue] = useState(initialValue);
|
|
|
|
if (value === undefined || value === null) {
|
|
return [defaultValue, setValue];
|
|
}
|
|
|
|
return [value, setValue];
|
|
};
|
|
|
|
export default useDefault;
|