Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@preact-hooks/instance

mihar-2217MIT1.0.6TypeScript support: included

A custom Preact Hook that provides a sensible alternative to useRef for storing instance variables.

instance, preact-hooks, preact, hooks, use-ref

readme

Preact Hooks - Instance

Inspired by donovan/use-instance

version MIT License

A custom Preact Hook that provides a sensible alternative to useRef for storing instance variables.


Table of Contents

Why?

See more in-depth explanation at: donovan/use-instance.

  • useRef is weird.
  • The fact that you have to access it via .current is strange.
  • You treat the object returned by useInstance just like you would this in a class component, so you're already familiar with how it works.
  • Use useRef if you're dealing with actual DOM elements.
  • Use useInstance for instance properties and methods.

Installation

This package has Preact 10+ as a peer dependency.

npm install @preact-hooks/instance or yarn add @preact-hooks/instance

You can also load it via the unpkg CDN

https://unpkg.com/@preact-hooks/instance will download the latest UMD bundle.

Docs

For usage and examples see donovan/use-instance.

LICENSE

MIT

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.0.6 (2019-10-02)

1.0.5 (2019-10-02)

Bug Fixes

  • build: upgrade microbundle (7f887e7)

1.0.4 (2019-10-02)

Bug Fixes

  • build: switch from mjs to esm extension and add browserslist (2eb0a7d)

1.0.3 (2019-10-02)

1.0.2 (2019-09-30)

Bug Fixes

  • npmrc: avoid locking package (1a02e23)

1.0.1 (2019-09-27)

Bug Fixes

  • build: name umd export correctly (e65a962)

1.0.0 (2019-09-25)