Coder Social home page Coder Social logo

c0d3t3k / jotai-devtools Goto Github PK

View Code? Open in Web Editor NEW
16.0 1.0 0.0 1.79 MB

Redux Devtools integrations for jotai.

Home Page: https://github.com/c0d3t3k/jotai-devtools

HTML 10.71% TypeScript 84.11% JavaScript 5.17%
jotai jotai-devtools redux-devtools react typescript

jotai-devtools's Introduction

Jotai Devtools

Sample GIF

About

Redux Devtools integration for Jotai. This library only supports the Redux Devtools browser extensions (Chrome, Edge and Firefox). It does not currently support the standalone app or the embedded component.

Installation

NPM Package is coming soon. In the meantime, use the following to install:

yarn add https://github.com/c0d3t3k/jotai-devtools.git

How to use

The Jotai Devtools library creates devtools integration instances on an atom by atom basis. To create a devtools instance, two parameters are required:

{
    // The display name for the atom
    name: "Count Atom (Hook)",

    // The atom to be mapped to a devtools instance
    atom: countAtom,
}

Also see the Dev.to Article, Sample Code and CodeSandBox

The library provides two methods to enable a devtools instance:

Hook Method

import React from 'react'

import { useAtom, atom } from 'jotai'
import { useJotaiDevtools, JotaiDevtools } from '@c0d3t3k/jotai-devtools'

// The atom to be monitored by the devtools.
const countAtom = atom(0)

const App: React.FC = () => {

    const [count, setCount] = useAtom(countAtom)

    // This hook maps the "Count Atom (Hook)" devtools instance to `countAtom`.
    useJotaiDevtools({
        name: "Count Atom (Hook)",
        atom: countAtom
    });

    // Some functions to modify `countAtom`
    const increment = () => {
        setCount(count + 1);
    }

    const decrement = () => {
        setCount(count - 1);
    }

    // The React component tree.
    return (
        <>
            <div>
                <h1>Count is {count}</h1>
                <button onClick={increment}>Increment Count</button>
                <button onClick={decrement}>Decrement Count</button>
            </div>
        </>
    )
}

Component Method

import React from 'react'

import { useAtom, atom } from 'jotai'
import { useJotaiDevtools, JotaiDevtools } from '@c0d3t3k/jotai-devtools'

// The atom to be monitored by the devtools.
const countAtom = atom(0)

const App: React.FC = () => {

    const [count, setCount] = useAtom(countAtom)

    // Some functions to modify `countAtom`
    const increment = () => {
        setCount(count + 1);
    }

    const decrement = () => {
        setCount(count - 1);
    }

    // The React component tree.
    return (
        <>
            {/* This component maps the "Count Atom (Component)" devtools instance to `countAtom`. */}
            <JotaiDevtools atom={countAtom} name="Count Atom (Component)"/>

            <div>
                <h1>Count is {count}</h1>
                <button onClick={increment}>Increment Count</button>
                <button onClick={decrement}>Decrement Count</button>
            </div>
        </>
    )
}

Development

To compile the code once, run

  • npm run build.

To compile the code once and refresh on file change, run

  • npm run start.

To publish the package to npm, make sure you're logged in the correct account by running

  • npm login.

Compile the package by running

  • npm run build

Update the package version accordingly by using

Then publish the package by running

  • npm publish

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.