Socket
Socket
Sign inDemoInstall

react-element-state

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-element-state

Easily manage element states like focus, hover and active states, without cluttering your React components


Version published
Maintainers
1
Created
Source

react-element-state

import ElementState from 'react-element-state';

<ElementState> is a React component that manages the 3 most common user interaction states, letting you focus on what to do with them. It provides:

  • isHovering (true/false) - whether the mouse is hovered over the element
  • isActive (true/false) - whether the mouse is pressed on the element
  • isFocused (true/false) - whether the element has the document focus

Usage

Pass a particular state to control your component:

<ElementState>
    {state => <MyButton highlight={state.isHovering}/>}
</ElementState>

If the prop names match up, spread all states onto your component:

<ElementState>
    {state => <MyButton {...state}/>}
</ElementState>

Or choose the states you care about and use them directly:

<ElementState>
    {({isFocused, isActive}) => {
        return <button>
            I'm {isFocused ? 'focused' : 'not focused'},
            and {isActive ? 'active' : 'not active'}
        </button>;
    }}
</ElementState>

Keywords

FAQs

Package last updated on 14 Jul 2016

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