3.1.1 • Published 2 months ago

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

Weekly downloads
-
License
ISC
Repository
github
Last release
2 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.1

2 months ago

3.1.0

2 months ago

3.0.8

3 months ago

3.0.7

5 months ago

3.0.4

9 months ago

3.0.6

8 months ago

3.0.5

8 months ago

3.0.1-next.0

1 year ago

3.0.1-next.1

1 year ago

2.0.2

1 year ago

3.0.3

11 months ago

3.0.2

12 months ago

3.0.1

1 year ago

3.0.0

1 year ago

1.1.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.1.1

1 year ago

1.0.2

2 years ago

1.1.0

1 year ago

1.0.1

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.0-alpha.0

2 years ago

1.0.1-next.1

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.15

1 year ago

1.0.14

2 years ago

1.0.13

2 years ago

0.2.5

2 years ago

1.0.12

2 years ago

0.2.4

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago