import { ref } from "vue";
import type { Ref, UnwrapRef } from "vue";

export type ReturnUseState<T> = [Ref<UnwrapRef<T>>, (newValue: UnwrapRef<T>) => UnwrapRef<T>];

export default function useState<T>(value: T): ReturnUseState<T> {
	const state = ref(value);
	const setState = (newValue: UnwrapRef<T>) => (state.value = newValue);
	return [state, setState];
}
