3.1.6 • Published 8 months ago

@equinor/fusion-framework-react-module v3.1.6

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

React Module

Concept

This module should provide React developers with utils for initializing and consume modules.

Usage

INTERNAL_MODULE

In general this package is implemented by framework/app scaffolding

  • @equinor/fusion-framework-react-app
  • @equinor/fusion-framework-react-framework

Requirements

  • React >= 17

this module requires React 17 or higher since the creation, configuration and initializing of modules are async. The provider must be wrapped in an Suspense components

Example

Create a provider component

import { Suspense } from 'react';

import http, { HttpModule } from '@equinor/fusion-framework-module-http';
import msal, { MsalModule } from '@equinor/fusion-framework-module-msal';

import { createModuleProvider } from '@equinor/fusion-framework-react-module';

export const ModuleProvider = createModuleProvider((config) => {
    config.auth.configureDefault({
        tenantId: 'MY_TENANT_ID',
        clientId: 'MY_CLIENT_ID',
        redirectUri: '/authentication/login-callback',
    });
    config.http.configureClient('foo', {
        baseUri: 'https://foo.bar',
        defaultScopes: ['FOO_CLIENT_ID/.default'],
    });
  },
  [http, msal]
)

Create a app component (consumer)

import { useModule } from '@equinor/fusion-framework-react-module';

const AppComponent = () => {
  const http = useModule('http');
  const client = http.createClient('foo');
  return (
    <button onClick={client.fetchAsync('/api/todo')}>Fetch todo</button>
  );
}

Render App

import ReactDOM from 'react-dom';

import { ModuleProvider } from './Provider';
import { AppComponent } from './AppComponent';

ReactDOM.render(
  <Suspense fallback={<span>Loading framework</span>}>
    <ModuleProvider>
      <AppComponent />
    </ModuleProvider>
  </Suspense>,
  document.getElementById('root')
);
3.1.3

11 months ago

3.1.2

1 year ago

3.1.6

9 months ago

3.1.5

9 months ago

3.1.4

10 months ago

3.1.1

1 year ago

3.1.0

1 year ago

3.0.8

1 year ago

3.0.7

2 years ago

3.0.4

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.1-next.0

2 years ago

3.0.1-next.1

2 years ago

2.0.2

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

1.1.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.1

3 years ago

1.0.2

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.0-alpha.0

3 years ago

1.0.1-next.1

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

0.2.5

3 years ago

1.0.12

3 years ago

0.2.4

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago