An open API service indexing awesome lists of open source software.

https://github.com/kimmelsg/cj-react-active

Handle open / closed state by listening to global events
https://github.com/kimmelsg/cj-react-active

Last synced: 2 months ago
JSON representation

Handle open / closed state by listening to global events

Awesome Lists containing this project

README

        

##react-active

```
npm install react-active
```

###What is this

react-active lets you handle open / closed states better in your app. It passes `active` and `setActive` to children. When you click outside of the children, active will be set to false. You can trigger active to be false by calling `setActive` yourself. I'm using this to better handle select inputs and make sure only one is active at a time.

###Usage

```js

{(active, setActive) => (
active ?

setActive(true)}>
Show this! It will hide on global window clicks.
setActive(false)}>
Hide this


:
//hide
)}

```

###API

- `active`: defaults to false
- `setActive`: accepts `true` or `false`

Clicking outside of the children will make `active` become false. May change to make clicking the children toggle active without you having to in the children.

###Todo

Possibly add other components. The current one will only allow one active component on the page. Maybe a component that returns active true / false on media query changes. I think the api for this is very simple, and if done right, could be really useful!