Skip to content

createRef()

Creates a MobX-aware ref that behaves like a callback ref and exposes observable current and meta fields.

Examples:

ts
const inputRef = createRef<HTMLInputElement>();
inputRef.set(document.createElement('input'));
ts
const ref = createRef<number>();
ref(3);
ref.current; // 3
ts
const nodeRef = createRef({
  onUnset: () => console.log('detached'),
  meta: { mounted: false },
});

Released under the MIT License.