@remote-ui/react
This library provides a custom React renderer that gives you the full power of React for your remote application, and provides an optional host layer that makes it easy for existing React apps to integrate a remote root. For a full overview of how `@remot
Last updated 2 days ago by shopify-dep .
MIT · Original npm · Tarball · package.json
$ cnpm install @remote-ui/react 
SYNC missed versions from official npm registry.

@remote-ui/react

This library provides a custom React renderer that gives you the full power of React for your remote application, and provides an optional host layer that makes it easy for existing React apps to integrate a remote root. For a full overview of how @remote-ui/react can fit in with the different pieces of remote-ui, you can refer to our comprehensive example.

Installation

Using yarn:

yarn add @remote-ui/react

or, using npm:

npm install @remote-ui/react --save

Usage

Remote environment

render()

The main entrypoint for this package, @remote-ui/react, provides the custom React renderer that outputs instructions to a @remote-ui/core RemoteRoot object. This lets you use the remote-ui system for communicating patch updates to host components over a bridge, but have React help manage your stateful application logic. To run a React ap against a RemoteRoot, use the render function exported by this library, passing in the remote root and your root React component:

// React usually has to be in scope when using JSX
import React from 'react';

// For convenience, this library re-exports several values from @remote-ui/core, like RemoteRoot
import {render, createRemoteRoot} from '@remote-ui/react';

// a host component — see implementation below for getting strong
// typing on the available props.
const Button = 'Button';

// Assuming we get a function that will communicate with the host...
const channel = () => {};

const remoteRoot = createRemoteRoot(channel, {
  components: [Button],
});

function App() {
  return <Button onClick={() => console.log('clicked!')}>Click me!</Button>;
}

render(<App />, remoteRoot);

As you add, remove, and update host components in your React tree, this renderer will output those operations to the RemoteRoot. Since remote components are just a combination of a name and allowed properties, they map exactly to React components, which behave the same way.

createRemoteReactComponent()

In the example above, our Button component was not strongly typed. Like with @remote-ui/core’s createRemoteComponent, We can use the createRemoteReactComponent function from this library to create a strongly typed component to use. @remote-ui/react’s API is the exact same as createRemoteComponent (including the same type arguments), but the value returned is both a RemoteComponentType and a ReactComponentType, both with appropriate prop types.

import {createRemoteReactComponent} from '@remote-ui/react';

const Button = createRemoteReactComponent<'Button', {onPress(): void}>(
  'Button',
);

// Type error, because onPress is missing!
const button = <Button>Save</Button>;

If you have a situation where you have separate packages for React and non-React components (e.g., to support the smaller bundle size of using only the core library), you can pass the result of calling @remote-ui/core’s createRemoteComponent to this version of the function, and the props will be inferred automatically.

import {createRemoteComponent as coreCreateRemoteComponent} from '@remote-ui/core';
import {createRemoteReactComponent} from '@remote-ui/react';

const Button = coreCreateRemoteComponent<'Button', {onPress(): void}>('Button');
const ReactButton = createRemoteReactComponent(Button);

// Still a type error!
const button = <Button>Save</Button>;

Host environment

TODO: explain exports of @remote-ui/react/host.

Other exports

This package exports a helper type for extracting information from components created by createRemoteComponent:

  • ReactPropsFromRemoteComponentType accepts any type as a type argument and, if it is a remote component, returns its prop types when used as a React component.

    import {
      createRemoteComponent,
      ReactPropsFromRemoteComponentType,
    } from '@remote-ui/react';
    
    const Button = createRemoteComponent<'Button', {onPress?(): void}>('Button');
    type ButtonProps = ReactPropsFromRemoteComponentType<typeof Button>; // {onPress?(): void; children: ReactNode}
    

Current Tags

  • 2.0.5                                ...           latest (2 days ago)
  • 0.0.41-alpha.0                                ...           next (5 months ago)

63 Versions

  • 2.0.5                                ...           2 days ago
  • 2.0.4                                ...           7 days ago
  • 2.0.3                                ...           20 days ago
  • 2.0.2                                ...           23 days ago
  • 2.0.1                                ...           23 days ago
  • 2.0.0                                ...           a month ago
  • 1.1.1                                ...           2 months ago
  • 1.1.0                                ...           2 months ago
  • 1.0.9                                ...           4 months ago
  • 1.0.8                                ...           4 months ago
  • 1.0.7                                ...           4 months ago
  • 1.0.6                                ...           4 months ago
  • 1.0.5                                ...           4 months ago
  • 1.0.4                                ...           4 months ago
  • 1.0.3                                ...           4 months ago
  • 1.0.2                                ...           4 months ago
  • 1.0.0                                ...           4 months ago
  • 1.0.1                                ...           4 months ago
  • 0.0.45                                ...           4 months ago
  • 0.0.44                                ...           4 months ago
  • 0.0.43                                ...           4 months ago
  • 0.0.42                                ...           4 months ago
  • 0.0.41                                ...           5 months ago
  • 0.0.41-alpha.0                                ...           5 months ago
  • 0.0.40                                ...           5 months ago
  • 0.0.39                                ...           5 months ago
  • 0.0.38                                ...           5 months ago
  • 0.0.37                                ...           5 months ago
  • 0.0.36                                ...           5 months ago
  • 0.0.35                                ...           5 months ago
  • 0.0.34                                ...           5 months ago
  • 0.0.33                                ...           5 months ago
  • 0.0.32                                ...           5 months ago
  • 0.0.31                                ...           5 months ago
  • 0.0.30                                ...           5 months ago
  • 0.0.29                                ...           5 months ago
  • 0.0.28                                ...           6 months ago
  • 0.0.27                                ...           6 months ago
  • 0.0.26                                ...           6 months ago
  • 0.0.25                                ...           6 months ago
  • 0.0.24                                ...           6 months ago
  • 0.0.23                                ...           6 months ago
  • 0.0.22                                ...           6 months ago
  • 0.0.21                                ...           6 months ago
  • 0.0.20                                ...           7 months ago
  • 0.0.19                                ...           7 months ago
  • 0.0.18                                ...           7 months ago
  • 0.0.17                                ...           7 months ago
  • 0.0.16                                ...           7 months ago
  • 0.0.15                                ...           9 months ago
  • 0.0.14                                ...           9 months ago
  • 0.0.13                                ...           9 months ago
  • 0.0.12                                ...           9 months ago
  • 0.0.11                                ...           9 months ago
  • 0.0.10                                ...           9 months ago
  • 0.0.9                                ...           9 months ago
  • 0.0.8                                ...           10 months ago
  • 0.0.7                                ...           10 months ago
  • 0.0.5                                ...           10 months ago
  • 0.0.4                                ...           10 months ago
  • 0.0.3                                ...           10 months ago
  • 0.0.2                                ...           10 months ago
  • 0.0.1                                ...           10 months ago

Copyright 2014 - 2017 © taobao.org |