All Projects → soywod → react-captain

soywod / react-captain

Licence: MIT License
⚓ A collection of strongly typed React hooks and contexts.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to react-captain

React-Combine-Provider
combine react providers in ease
Stars: ✭ 29 (+93.33%)
Mutual labels:  react-context, react-hooks
tacklebox
🎣React UX components for handling common interactions
Stars: ✭ 15 (+0%)
Mutual labels:  collection, react-hooks
Constate
React Context + State
Stars: ✭ 3,519 (+23360%)
Mutual labels:  react-context, react-hooks
react-emotion-multi-step-form
React multi-step form library with Emotion styling
Stars: ✭ 25 (+66.67%)
Mutual labels:  react-context, react-hooks
React-Playground
Learning reactjs from the ground up (router, redux, thunk, hooks, context, portals, and functional components)
Stars: ✭ 15 (+0%)
Mutual labels:  react-context, react-hooks
react-abac
Attribute Based Access Control for React
Stars: ✭ 54 (+260%)
Mutual labels:  react-context, react-hooks
react-change-highlight
✨ a react component to highlight changes constantly ⚡️
Stars: ✭ 79 (+426.67%)
Mutual labels:  react-hooks
whatdevsneed
Discover new developer tools 🧰
Stars: ✭ 48 (+220%)
Mutual labels:  collection
window-scroll-position
React hook for Window scroll position
Stars: ✭ 81 (+440%)
Mutual labels:  react-hooks
Fakeflix
Not the usual clone that you can find on the web.
Stars: ✭ 4,429 (+29426.67%)
Mutual labels:  react-hooks
react-store
A library for better state management in react hooks world
Stars: ✭ 34 (+126.67%)
Mutual labels:  react-hooks
how-react-hooks-work
Understand how React-hook really behaves, once and for all!
Stars: ✭ 73 (+386.67%)
Mutual labels:  react-hooks
laravel-any
🏓 Laravel collection macro that determine if `any` item from the collection passes the given truth test.
Stars: ✭ 38 (+153.33%)
Mutual labels:  collection
Facebook-Messenger
This is a Facebook Messenger clone.You can comminicate to other at realtime.Used ReactJS, Material UI, Firebase, Firestore Database
Stars: ✭ 18 (+20%)
Mutual labels:  react-hooks
atomic-state
A decentralized state management library for React
Stars: ✭ 54 (+260%)
Mutual labels:  react-hooks
CoolSlidingMenu
A powerful menu that you can customize it。
Stars: ✭ 25 (+66.67%)
Mutual labels:  collection
react-hook-form-auto
Automatic form generation using ReactHookForm
Stars: ✭ 45 (+200%)
Mutual labels:  react-hooks
HBHybridCollectionView
Instead for SwipeTableView when using collection view.
Stars: ✭ 14 (-6.67%)
Mutual labels:  collection
react-social-network
react social network
Stars: ✭ 13 (-13.33%)
Mutual labels:  react-hooks
frontegg-react
Frontegg-React is pre-built Component for faster and simpler integration with Frontegg services.
Stars: ✭ 15 (+0%)
Mutual labels:  react-hooks

React Captain Build Status codecov npm

A collection of strongly typed React hooks and contexts.

Live demo at https://react-captain.soywod.me.

Table of contents

Installation

yarn add react-captain
# or
npm install react-captain

Examples

Live demo at https://react-captain.soywod.me.

Click outside

Capture click event outside of the given HTMLElement.

import {useClickOutside} from "react-captain"

const Component: FC = () => {
  const ref = useRef<HTMLDivElement | null>(null)
  useClickOutside(ref, () => console.log("Clicked outside!"))

  return (
    <div ref={ref}>
      Click outside
    </div>
  )
}

Debounce

Add debounce to a handler.

import {useDebounce} from "react-captain"

function Component() {
  const handler = useDebounce(() => console.log("Hello!"), 1000)

  return (
    <>
      <button onClick={handler}>
        Say hello with delay
      </button>
      <button onClick={handler.abort}>
        Abort
      </button>
      <button onClick={handler.terminate}>
        Terminate
      </button>
    </>
  )
}

Timeout

A wrapper around setTimeout.

import {useTimeout} from "react-captain"

function Component() {
  const handler = useTimeout(() => console.log("Hello!"), 1000)

  return (
    <>
      <button onClick={handler}>
        Say hello with delay
      </button>
      <button onClick={handler.abort}>
        Abort
      </button>
      <button onClick={handler.terminate}>
        Terminate
      </button>
    </>
  )
}

Interval

A wrapper around setInterval, using toggle.

import {useInterval} from "react-captain"

function Component() {
  const [isOn, toggle] = useInterval(() => console.log("Hello!"))

  return (
    <button onClick={handler}>
      {isOn ? "Stop" : "Say hello"}
    </button>
  )
}

Stored state

A persistant useState, based on React's useState and localForage. Drivers supported: localStorage, WebSQL and IndexedDB.

import {useStoredState} from "react-captain"

function Component() {
  const [value, setValue] = useStoredState("storage-key", "Default value")

  return (
    <button onClick={() => setValue("Value changed!")}>
      {String(value)}
    </button>
  )
}

Toggle

A useState for booleans.

import {useToggle} from "react-captain"

const Component: FC = () => {
  const [isOn, toggle] = useToggle(false)

  return (
    <div>
      <button onClick={toggle}>
        Switch status: {isOn ? "ON" : "OFF"}
      </button>
      <button onClick={() => toggle(false)}>
        Reset toggle
      </button>
    </div>
  )
}

Subject

A wrapper around rxjs.Subject.

import {useSubject} from "react-captain"
import {Subject} from "rxjs"

const subject$ = new Subject<number>()

const Component: FC = () => {
  const [counter, setCounter] = useState(0)
  useSubject(subject$, setCounter)
  return <button onClick={() => subject$(counter + 1)}>{counter}</button>
}

Behavior subject

A wrapper around rxjs.BehaviorSubject.

import {useBehaviorSubject} from "react-captain"
import {BehaviorSubject} from "rxjs"

const subject$ = new BehaviorSubject(0)

const Component: FC = () => {
  const [counter, setCounter] = useBehaviorSubject(subject$, counter => {
    console.log("New counter received:", counter)
  })

  return <button onClick={() => setCounter(counter + 1)}>{counter}</button>
}

Development

git clone https://github.com/soywod/react-captain.git
cd react-captain
yarn install

To start the development server:

yarn start

To build the lib:

yarn build

To build the demo:

yarn build:demo

Tests

Unit tests

Unit tests are handled by Jest (.test files) and React Testing Library (.spec files).

yarn test:unit

End-to-end tests

End-to-end tests are handled by Cypress (.e2e files).

yarn start
yarn test:e2e

Changelog

See CHANGELOG.md.

License

MIT - Copyright © 2019-2020 soywod.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].
OSZAR »