A small React hook for managing mutable and reactive state with direct access through .current.
1.0.0 – Initial Release:
- Supports all value types
- Reactive updates through
.tick - Lightweight and dependency-free
- Reactive mutable reference via
.current - Auto re-render on value change
- Works with any type
- TypeScript ready
npm install react-use-currentor
yarn add react-use-currentimport useCurrent from 'react-use-current';
export default function Counter() {
const count = useCurrent(0);
return (
<button onClick={() => (count.current += 1)}>
Count: {count.current}
</button>
);
}import useCurrent from 'react-use-current';
export default function ListExample() {
const data = useCurrent({ arr: [] as string[], map: new Map() });
function addItem() {
data.current.arr.push('Item ' + (data.current.arr.length + 1));
}
return (
<div>
{data.current.arr.map((item) => (
<p key={item}>{item}</p>
))}
<button onClick={addItem}>Add Item</button>
</div>
);
}Creates a reactive reference with optional initial value.
const value = useCurrent('Hello');| Property | Type | Description |
|---|---|---|
| current | any | Holds the current value (read/write). |
| tick | number | Increases automatically when the value changes. |
- Works seamlessly with any type.
- Ideal for reactive logic without using traditional
useState. - Minimal and framework-consistent behavior.
MIT License © 2025 John Soatra