Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

use-service

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-service

`useService` react hook. Share a state and an API with multiple components

Source
npmnpm
Version
0.3.0-1
Version published
Weekly downloads
1
Maintainers
2
Weekly downloads
 
Created
Source

useService react hook

React hook to handle a shared service accross multiple components.

By service we point an instance of a user-defined object using the new operator.

A service may hold a state. That state will be shared to your components. That means your components will be udpated if the service notify it has been updated.

Getting started

just add use-service addon to your project:

npm i use-service

Then you can follow the example at https://github.com/toutpt/use-service/tree/master/src/App.js

example

API

registerService(idOrFunction, func) -> undefined

you have two options:

function $foo() {}
registerService('$foo', $foo);

or

function $foo() {}
$foo.id = '$foo';
registerService($foo);

useService(id, options) -> service instance

options.subscribe is set by default to true. In case performance are important you can set it to false if you know your component do not display the data of this service.

Keywords

react

FAQs

Package last updated on 02 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts