498

useRefState

Hook that returns the state reference of the value

statelowtest coverage
Disabled
import { useRefState } from '@siberiacancode/reactuse';

const Demo = () => {
  const enabled = useRefState(false);

  return (
    <section className='flex flex-col items-center gap-3 p-8'>
      <input
        checked={enabled.current}
        role='switch'
        type='checkbox'
        onChange={() => (enabled.current = !enabled.current)}
      />

      <span className='text-muted-foreground text-sm'>
        {enabled.current ? 'Enabled' : 'Disabled'}
      </span>
    </section>
  );
};

export default Demo;

Installation

pnpm add @siberiacancode/reactuse

Usage

const internalRefState = useRefState();

Type Declarations

export interface StateRef<Value> {
  (node: Value): void;
  current: Value;
  state?: Value;
}

API

Parameters

NameTypeDefaultNote
initialValueValue-The initial value

Returns

StateRef<Value>

Contributors

ddebabinAAlexander Lee

Last updated on