Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@backium/use-instance

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@backium/use-instance

Library to get Object Instances via context. It can be useful when you want to access your object instances from other React components.

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

use-instance

Library to get Object Instances via context. It can be useful when you want to access your object instances from other React components.

Installation

In order to install the package. use the following command:

yarn add @backium/use-instance

Usage

First, you should add InstanceProvider.

import { InstanceProvider } from '@backium/use-instance';
import App from './App';

export default () => {
  return (
    <InstanceProvider>
      <App />
    </InstanceProvider>
  );
};

Add object instance to the store

import { InstanceProvider, useInstance } from '@backium/use-instance';
import SomeComponent from './SomeComponent';

class SecretManager {
  get() {
    return 'supersecret';
  }
}

const App = () => {
  const { setInstance } = useInstance();
  const secretManager = new SecretManager();
  React.useEffect(() => {
    setInstance('secretManager', secretManager);
  }, []);
  return <SomeComponent />;
};

Use object instance from another component

import { useInstance } from '@backium/use-instance';

const SomeComponent = () => {
  const [secret, setSecret] = React.useState('');
  const { instances, getInstance } = useInstance();
  React.useEffect(() => {
    const instance = getInstance<SecretManager>('secretManager');
    const secretText = instance?.get();
    if (secretText) {
      setSecret(secretText);
    }
  }, [instances]);
  return <div>{secret}</div>;
};

export default SomeComponent;

FAQs

Package last updated on 15 Mar 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc