import React from 'react'; export function useControllableProp(prop: T | undefined, state: T) { const { current: isControlled } = React.useRef(prop !== undefined); const value = isControlled && typeof prop !== 'undefined' ? prop : state; return [isControlled, value] as const; }