1.0.5 • Published 3 years ago

use-global-service v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

use-global-service

use-global-service is React hook. This package aims to help users of React to use Singleton Service Class (implementing business logic)

Installation

# npm
npm i use-global-service

# yarn
yarn add use-global-service

Example

App.js

import React from "react";
import { GlobalServiceProvider } from "use-global-service";

function App() {
  return (
    // Class stored by Map
    <GlobalServiceProvider>
      <div>hello world</div>
    </GlobalServiceProvider>
  );
}

export default App;

businessClass.js or ts

class Business {
  constructor() {}

  work() {
    console.log("hello world");
  }
}

export default Business;

AnyComponent.js

import { useEffect } from "react";
import { useGlobalService } from "use-global-service";
import Business from "./s";
function AnyComponent() {
  const business = useGlobalService(Business); // always singleton
  useEffect(() => {
    business.work();
  }, []);

  return <div></div>;
}
1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago