React hook that allows any component handle controlled and uncontrolled modes, and provide control over its internal state.

Most Nature UI components use the useControllableState for seamlessly managing both controlled or uncontrolled state scenarios.


import { useControllableProp, useControllableState } from '@nature-ui/core';


Given a prop value and state value, the useControllableProp hook is used to determine whether a component is controlled or uncontrolled, and also returns the computed value.

  • It returns the prop value if the component is controlled
  • It returns the state value if the component if uncontrolled


const [isControlled, value] = useControllableProp(propValue, stateValue);


The useControllableState hook returns the state and function that updates the state, just like React.useState does.

const [value, setValue] = useControllableState(options);


With useControllableState, you can pass an initial state (using defaultValue) implying the component is uncontrolled, or you can pass a controlled value (using value) implying the component is controlled.

Here's an example of an uncontrolled state.

Editable Example

Here's an example of a controlled state.

Editable Example

Contextual feedback and State updates#

This hook provides helpful error or warning messages when you switch between controlled or uncontrolled modes or when you attempt to update the defaultValue passed.


defaultValueT \| (() => T)-The initial value to be used, in uncontrolled mode
namestring-The component name (for warnings)
onChange((value: T) => void)-The callback fired when the value changes
valueT-The value to used in controlled mode