@nfq/autobind
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

@nfq/autobind

EsLint License: MIT


  1. Description
  2. Getting started
    1. Installation
  3. Usage
  4. Support

Description: License: MIT

The @nfq/autobind package provides a decorator function for automatically binding class methods to the instance of the class. This ensures the correct context (this value) is maintained, especially useful when passing methods as callbacks. It is designed to streamline method binding in JavaScript and TypeScript applications, particularly beneficial in React components and other class-based structures.

(back to top)


Getting started

To install the package locally follow the next steps:

Installation

To install the package run

npm install @nfq/autobind

if you are on yarn

yarn add @nfq/autobind

or on pnpm

pnpm install @nfq/autobind

Usage

The @autobind decorator can be used in class components to ensure that methods are bound to the instance of the class. This is especially useful when passing methods as callbacks.

import {autobind} from '@nfq/autobind';

class MyClass {
  @autobind
  myMethod() {
    // This method is automatically bound to instances of MyClass.
  }
}

(back to top)


Support

Christoph Kruppe - [https://github.com/ckruppe] - c.kruppe@nfq.de

(back to top)

Readme

Keywords

none

Package Sidebar

Install

npm i @nfq/autobind

Weekly Downloads

84

Version

1.1.3

License

MIT

Unpacked Size

15.6 kB

Total Files

10

Last publish

Collaborators

  • nfqdbt