Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@reach/portal
Advanced tools
@reach/portal is a React component that allows you to render children into a DOM node that exists outside the DOM hierarchy of the parent component. This is useful for creating modals, tooltips, and other UI elements that need to visually break out of their container.
Basic Portal Usage
This example demonstrates the basic usage of the @reach/portal package. The `Portal` component is used to render a div outside of the parent DOM hierarchy, which can be useful for creating modals or tooltips.
import React from 'react';
import { Portal } from '@reach/portal';
function App() {
return (
<div>
<h1>My App</h1>
<Portal>
<div style={{ position: 'absolute', top: 0, left: 0, background: 'white', border: '1px solid black' }}>
This is rendered in a portal!
</div>
</Portal>
</div>
);
}
export default App;
Nested Portals
This example shows how you can nest portals within each other. The nested `Portal` component renders its children outside of the parent DOM hierarchy, allowing for complex UI structures.
import React from 'react';
import { Portal } from '@reach/portal';
function App() {
return (
<div>
<h1>My App</h1>
<Portal>
<div style={{ position: 'absolute', top: 0, left: 0, background: 'white', border: '1px solid black' }}>
This is rendered in a portal!
<Portal>
<div style={{ position: 'absolute', top: 20, left: 20, background: 'lightgray', border: '1px solid black' }}>
This is a nested portal!
</div>
</Portal>
</div>
</Portal>
</div>
);
}
export default App;
The `react-dom` package provides the `createPortal` method, which allows you to render children into a DOM node that exists outside the DOM hierarchy of the parent component. It is a core part of React and offers similar functionality to @reach/portal but is more integrated into the React ecosystem.
The `react-portal` package is another popular library for creating portals in React. It offers a simple API and additional features like event handling and portal management. It is more feature-rich compared to @reach/portal but may be overkill for simple use cases.
The `react-reverse-portal` package allows you to create portals that can be moved around the DOM dynamically. It provides more advanced features for managing portal content and is useful for complex applications that require dynamic portal management. It offers more flexibility compared to @reach/portal.
Creates and appends a DOM node to the end of document.body
and renders a React tree into it. Useful for rendering a natural React element hierarchy with a different DOM hierarchy to prevent parent styles from clipping or hiding content (for popovers, dropdowns, and modals).
import { Portal } from "@reach/portal";
function Example() {
return (
<Portal>
<div>Stuff goes here</div>
</Portal>
);
}
FAQs
Declarative portals for React
The npm package @reach/portal receives a total of 421,005 weekly downloads. As such, @reach/portal popularity was classified as popular.
We found that @reach/portal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.