# react-gateway
**Repository Path**: mirrors_cloudflare/react-gateway
## Basic Information
- **Project Name**: react-gateway
- **Description**: Render React DOM into a new context (aka "Portal")
- **Primary Language**: Unknown
- **License**: BSD-3-Clause
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-08-08
- **Last Updated**: 2026-02-28
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 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`](https://github.com/cloudflare/react-modal2).
It also works in universal (isomorphic) React applications without any
additional setup and in React Native applications
[when used correctly](#react-native-example).
## Installation
```sh
$ npm install --save react-gateway
```
## Example
```js
import React from 'react';
import {
Gateway,
GatewayDest,
GatewayProvider
} from 'react-gateway';
export default class Application extends React.Component {
render() {
return (
React Gateway Universal Example
);
}
}
```
Will render as:
```js
React Gateway Universal Example
```
## Usage
To get started with React Gateway, first wrap your application in the
``.
```diff
import React from 'react';
+ import {
+ GatewayProvider
+ } from 'react-gateway';
export default class Application extends React.Component {
render() {
return (
+
{this.props.children}
+
);
}
}
```
Then insert a `` whereever you want it to render and give it a
name.
```diff
import React from 'react';
import {
GatewayProvider,
+ GatewayDest
} from 'react-gateway';
export default class Application extends React.Component {
render() {
return (
{this.props.children}
+
);
}
}
```
Then in any of your components (that get rendered inside of the
``) add a ``.
```diff
import React from 'react';
+ import {Gateway} from 'react-gateway';
export default class MyComponent extends React.Component {
render() {
return (
+
+ Will render into the "global" gateway.
+
);
}
}
```
If you want to customize the `` 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.
```diff
export default class Application extends React.Component {
render() {
return (
{this.props.children}
-
+
);
}
}
```
## 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 `` and passed to `` and
`` 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 ``.**
Because if you don't, `` will try to render `div` element, which
is not available.
```js
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 (
React Gateway Native Example
Text rendered elsewhere
);
}
}
```