
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
react-gateway
Advanced tools
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.
$ npm install --save react-gateway
import React from 'react';
import {
Gateway,
GatewayDest,
GatewayProvider
} from 'react-gateway';
export default class Application extends React.Component {
render() {
return (
<GatewayProvider>
<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>
<Gateway into="one">
<div className="item">Item 3</div>
</Gateway>
<div className="item">Item 4</div>
</div>
<GatewayDest name="one" tagName="section" className="hello"/>
<GatewayDest name="two"/>
</GatewayProvider>
);
}
}
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 tagName
, 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" tagName="section" className="global-gateway"/>
</div>
</GatewayProvider>
);
}
}
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.
FAQs
Render React DOM into a new context
The npm package react-gateway receives a total of 1,823 weekly downloads. As such, react-gateway popularity was classified as popular.
We found that react-gateway demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.