Giter VIP home page Giter VIP logo

reinspect's Introduction

reinspect

Under development

Connect React state hooks (useState and useReducer) to redux dev tools.

See it live

useState with Redux dev tools

Why?

Hooks are great, they are a joy to use to create state in components. On the other hand, with something global and centralised like Redux, we have great dev tools.

Why not both? That's exactly what this package offers: connecting useState and useReducer to redux dev tools, so you can do the following:

  • Inspect actions and state for each hook
  • Time travel through state changes in your app
  • Hot reloading: save your current state and re-inject it when re-rendering

API

You need redux devtools installed. This package provides:

  • StateInspector: a provider which will be used by useState and useReducer to connect them to a store and redux dev tools.

    • It accepts optionally a name (name of the store in dev tools) and initialState (if you want to start with a given state)
    • You can have more than one StateInspector in your application, hooks will report to the nearest one
    • Without a StateInspector, useState and useReducer behave normally
    import React from "react"
    import { StateInspector } from "reinspect"
    import App from "./App"
    
    function AppWrapper() {
        return (
            <StateInspector name="App">
                <App />
            </StateInspector>
        )
    }
    
    export default AppWrapper
  • useState(initialState, id): like useState but with a 2nd argument id (a unique ID to identify it in dev tools). If no id is supplied, the hook won't be connected to dev tools.

    import React from "react"
    import { useState } from "reinspect"
    
    export function CounterWithUseState({ id }) {
        const [count, setCount] = useState(0, id)
    
        return (
            <div>
                <button onClick={() => setCount(count - 1)}>-</button>
                {count} <button onClick={() => setCount(count + 1)}>+</button>
            </div>
        )
    }
  • useReducer(reducer, initialState, id): like useReducer but with a 3rd argument id (a unique ID to identify it in dev tools). If no id is supplied, the hook won't be connected to dev tools.

reinspect's People

Contributors

pau1fitz avatar troch avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.