1.0.6 • Published 6 months ago

@connectifi/agent-react v1.0.6

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
6 months ago

Connectifi Agent for React

The Connectifi Agent for React is a react friendly wrapper around the web agent.

  • AgentImportProvider - top level react context provider that facilitates importing the agent from the interop server
  • AgentProvider - lower level react context provider that exposes the instance of the agent to child components
  • useConnectifiAgent - hook that creates/returns the agent instance

Getting started

To get started, simply install the module into your application:

npm install @connectifi/agent-react

Using the components

The first thing to do is setup the AgentImportProvider at the top level (or very high) of your component hierarchy. For example, a good place to put this is where you handle any UI themeing. After that, a page level component that uses the AgentProvider and useConnectifiAgent hook in tandem.

The AgentImportProvider

This sets up the import context used by the useConnectifiAgent hook. it is best to put this at the top of the app's component hierarchy. For example, if using next.js, this provider component would go in /pages/_app.tsx (or /app/layout.tsx if using the app router).

import { AgentImportProvider } from '@connectifi/agent-react';

...

function MyApp({ Component, pageProps }: AppProps) {
  const interopUrl = 'https://platform.connectifi.app';

  return (
    <AgentImportProvider interopUrl={interopUrl}>
      <Component {...pageProps} />
    </AgentImportProvider>
  ) : null;
}

The AgentProvider and useConnectifiAgent hook

The AgentProvider and hook work together to provide all the child components with a reference to the instantiated FDC3 api as well as provide current agent status etc.

import { AgentProvider, useConnectifiAgent } from '@connectifi/agent-react';

...
interface Props {
  children: ReactElement | ReactElement[];
}

export function AgentPageLayout({ children }: Props) {
  const agent = useConnectifiAgent({ appId: 'myApp@12345678' });

  return (
    <div>
      <AgentProvider agent={agent}>
        {children}
      </AgentProvider>
      <CustomAgentUI agent={agent} />
    </div>
  );
}
1.0.6

6 months ago

1.0.5-beta.1

6 months ago

1.0.5-beta.0

6 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.2-beta.0

7 months ago

1.0.1

10 months ago

1.0.1-beta.2

10 months ago

1.0.1-beta.1

10 months ago

1.0.1-beta.0

10 months ago

1.0.0

10 months ago

0.0.2-beta.0

10 months ago

0.0.1

10 months ago

0.0.1-beta.5

10 months ago

0.0.1-beta.4

10 months ago

0.0.1-beta.3

10 months ago

0.0.1-beta.2

10 months ago

0.0.1-beta.0

10 months ago