Skip to content
This repository has been archived by the owner on Sep 17, 2022. It is now read-only.

mihar-22/preact-hooks-instance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published