Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-popper

Package Overview
Dependencies
Maintainers
2
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-popper

Official library to use Popper on React projects

  • 2.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is react-popper?

The react-popper package is a React wrapper around the Popper.js library, which is a positioning engine to ensure popovers, tooltips, and similar floating elements are positioned correctly relative to their reference elements, even in complex scenarios like inside scrolling containers or when the viewport size changes. It provides a set of React hooks and components to integrate Popper.js functionality in a React-friendly way.

What are react-popper's main functionalities?

Tooltip positioning

This code demonstrates how to use the `usePopper` hook to create a tooltip that is positioned relative to a button. The tooltip's position is automatically updated to ensure it remains correctly placed relative to the button, even if the layout changes.

{"import React from 'react';\nimport { usePopper } from 'react-popper';\n\nfunction Tooltip() {\n  const [referenceElement, setReferenceElement] = useState(null);\n  const [popperElement, setPopperElement] = useState(null);\n  const { styles, attributes } = usePopper(referenceElement, popperElement);\n\n  return (\n    <>\n      <button ref={setReferenceElement}>Hover over me</button>\n      <div ref={setPopperElement} style={styles.popper} {...attributes.popper}>\n        Tooltip content\n      </div>\n    </>\n  );\n}"}

Dropdown menu

This example shows how to create a dropdown menu using `usePopper`. The dropdown's visibility is toggled by clicking a button, and its position is dynamically adjusted to stay aligned with the button.

{"import React, { useState } from 'react';\nimport { usePopper } from 'react-popper';\n\nfunction Dropdown() {\n  const [referenceElement, setReferenceElement] = useState(null);\n  const [popperElement, setPopperElement] = useState(null);\n  const [visible, setVisible] = useState(false);\n  const { styles, attributes } = usePopper(referenceElement, popperElement);\n\n  return (\n    <>\n      <button ref={setReferenceElement} onClick={() => setVisible(!visible)}>Toggle Dropdown</button>\n      {visible && (\n        <div ref={setPopperElement} style={styles.popper} {...attributes.popper}>\n          Dropdown content\n        </div>\n      )}\n    </>\n  );\n}"}

Other packages similar to react-popper

Keywords

FAQs

Package last updated on 28 Apr 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc