react-gateway

WebJar for react-gateway

Лицензия

Лицензия

Категории

Категории

React Взаимодействие с пользователем Веб-фреймворки
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

react-gateway
Последняя версия

Последняя версия

2.2.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

react-gateway
WebJar for react-gateway
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/cloudflare/react-gateway

Скачать react-gateway

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/react-gateway/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>react-gateway</artifactId>
    <version>2.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/react-gateway/
implementation 'org.webjars.npm:react-gateway:2.2.0'
// https://jarcasting.com/artifacts/org.webjars.npm/react-gateway/
implementation ("org.webjars.npm:react-gateway:2.2.0")
'org.webjars.npm:react-gateway:jar:2.2.0'
<dependency org="org.webjars.npm" name="react-gateway" rev="2.2.0">
  <artifact name="react-gateway" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='react-gateway', version='2.2.0')
)
libraryDependencies += "org.webjars.npm" % "react-gateway" % "2.2.0"
[org.webjars.npm/react-gateway "2.2.0"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
org.webjars.npm : react jar [0.14.2,0.15),[15.0.0-0,16)
org.webjars.npm : react-prop-types jar [0.3.0,0.4)

Модули Проекта

Данный проект не имеет модулей.

React Gateway

Render React DOM into a new context (aka "Portal")

This can be used to implement various UI components such as modals. See react-modal2.

It also works in universal (isomorphic) React applications without any additional setup and in React Native applications when used correctly.

Installation

$ npm install --save react-gateway

Example

import React from 'react';
import {
  Gateway,
  GatewayDest,
  GatewayProvider
} from 'react-gateway';

export default class Application extends React.Component {
  render() {
    return (
      <GatewayProvider>
        <div>
          <h1>React Gateway Universal Example</h1>
          <div className="container">
            <Gateway into="one">
              <div className="item">Item 1</div>
            </Gateway>
            <Gateway into="two">
              <div className="item">Item 2</div>
            </Gateway>
            <div className="item">Item 3</div>
          </div>
          <GatewayDest name="one" component="section" className="hello"/>
          <GatewayDest name="two"/>
        </div>
      </GatewayProvider>
    );
  }
}

Will render as:

<div>
  <h1>React Gateway Universal Example</h1>
  <div className="container">
    <noscript></noscript>
    <noscript></noscript>
    <div className="item">Item 3</div>
  </div>
  <section className="hello">
    <div className="item">Item 1</div>
  </section>
  <div>
    <div className="item">Item 2</div>
  </div>
</div>

Usage

To get started with React Gateway, first wrap your application in the <GatewayProvider>.

  import React from 'react';
+ import {
+   GatewayProvider
+ } from 'react-gateway';

  export default class Application extends React.Component {
    render() {
      return (
+       <GatewayProvider>
          <div>
            {this.props.children}
          </div>
+       </GatewayProvider>
      );
    }
  }

Then insert a <GatewayDest> whereever you want it to render and give it a name.

  import React from 'react';
  import {
    GatewayProvider,
+   GatewayDest
  } from 'react-gateway';

  export default class Application extends React.Component {
    render() {
      return (
        <GatewayProvider>
          <div>
            {this.props.children}
+           <GatewayDest name="global"/>
          </div>
        </GatewayProvider>
      );
    }
  }

Then in any of your components (that get rendered inside of the <GatewayProvider>) add a <Gateway>.

  import React from 'react';
+ import {Gateway} from 'react-gateway';

  export default class MyComponent extends React.Component {
    render() {
      return (
        <div>
+         <Gateway into="global">
+           Will render into the "global" gateway.
+         </Gateway>
        </div>
      );
    }
  }

If you want to customize the <GatewayDest> element, you can pass any props, including component (which will allows you to specify a tagName or custom component), and they will be passed to the created element.

  export default class Application extends React.Component {
    render() {
      return (
        <GatewayProvider>
          <div>
            {this.props.children}
-           <GatewayDest name="global"/>
+           <GatewayDest name="global" component="section" className="global-gateway"/>
          </div>
        </GatewayProvider>
      );
    }
  }

How it works

React Gateway works very differently than most React "portals" in order to work in server-side rendered React applications.

It maintains an internal registry of "containers" and "children" which manages where things should be rendered.

This registry is created by <GatewayProvider> and passed to <Gateway> and <GatewayDest> invisibly via React's contextTypes.

Whenever a child or container is added or removed, React Gateway will update its internal registry and ensure things are properly rendered.

React Native example

React Gateway does not directly depend on react-dom, so it works fine with React Native under one condition:

You must pass React Native component like View or similar to component prop of <GatewayDest>.

Because if you don't, <GatewayDest> will try to render div element, which is not available.

import React from 'react';
import { Text, View } from 'react-native';
import {
  Gateway,
  GatewayDest,
  GatewayProvider
} from 'react-gateway';

export default class Application extends React.Component {
  render() {
    return (
      <GatewayProvider>
        <View>
          <Text>React Gateway Native Example</Text>
          <View>
            <Gateway into="one">
              <Text>Text rendered elsewhere</Text>
            </Gateway>
          </View>
          <GatewayDest name="one" component={View} />
        </View>
      </GatewayProvider>
    );
  }
}
org.webjars.npm

Cloudflare

Версии библиотеки

Версия
2.2.0