himself65 / jotai-devtools

A powerful toolkit to enhance your development experience with Jotai

Home Page:https://jotai.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Jotai DevTools

Build Status Version

πŸš€ Features

  • Debug 🐞 atom values with ease
  • Out-of-the-box πŸ”Œ support for async/suspendible atoms
  • Built-in Dark mode πŸŒ—
  • βœ… Supports custom store
  • βœ… Works with provider-less mode
  • βœ… Works with Next.js
  • βœ… Supports custom nonce for CSP
  • βœ… Hides private atoms with ability to configure (requires Jotai >=2.0.3)
  • βœ… Tree-shakable and built for non-production environments

πŸ“Ί Preview

Jotai DevTools Screenshot

☝️ Prerequisites

  • Jotai version >=1.11.0 (highly recommended to use 2.x.x)
  • React version >=17.0.0

πŸ“¦ Setup

# yarn
yarn add jotai-devtools

# npm
npm install jotai-devtools --save

✨ UI DevTools

Enhance your development experience with the UI based Jotai DevTool

Demo

Babel plugin setup - (Optional but highly recommended)

Use Jotai babel plugins for optimal debugging experience. Find the complete guide on jotai.org

Eg.

{
  "plugins": [
    // Enables hot reload for atoms
    "jotai/babel/plugin-react-refresh",
    // Automatically adds debug labels to the atoms
    "jotai/babel/plugin-debug-label"
  ]
}

Next JS setup

You may skip this section if you're not using Next.js.

Enable transpilePackages for the UI CSS and components to be transpiled correctly.

// next.config.ts

const nextConfig = {
  // Learn more here - https://nextjs.org/docs/advanced-features/compiler#module-transpilation
  // Required for font css to be imported correctly πŸ‘‡
  transpilePackages: ['jotai-devtools'],
};

module.exports = nextConfig;

Available props

type DevToolsProps = {
  // Defaults to false
  isInitialOpen?: boolean;
  // pass a custom store
  store?: Store;
  // Defaults to light
  theme?: 'dark' | 'light';
  // Custom nonce to allowlist jotai-devtools specific inline styles via CSP
  nonce?: string;
  options?: {
    // Private atoms are used internally in atoms like `atomWithStorage` or `atomWithLocation`, etc. to manage state.
    // Defaults to `false`
    shouldShowPrivateAtoms?: boolean;
  };
};

Provider-less

import { DevTools } from 'jotai-devtools';

const App = () => {
  return (
    <>
      <DevTools />
      {/* your app */}
    </>
  );
};

With Provider

import { createStore } from 'jotai';
import { DevTools } from 'jotai-devtools';

const customStore = createStore();

const App = () => {
  return (
    <Provider store={customStore}>
      <DevTools store={customStore} />
      {/* your app */}
    </Provider>
  );
};

Hooks

Detailed documentation is available on https://jotai.org/docs/api/devtools

import {
  useAtomsSnapshot,
  useGotoAtomsSnapshot,
  useAtomsDebugValue,
  // Redux devtool hooks
  useAtomDevtools,
  useAtomsDevtools,
} from 'jotai-devtools';

Migration guides

Migrate Jotai to V2

Find the official migration guide on jotai.org

Migrate jotai/react/devtools to jotai-devtools

  1. Install this package

    # npm
    npm install jotai-devtools --save
    
    # yarn
    yarn add jotai-devtools
  2. Update imports from jotai/react/devtools to jotai-devtools

    import {
     useAtomsSnapshot,
     useGotoAtomsSnapshot,
     useAtomsDebugValue,
     // Redux devtool integration hooks
     useAtomDevtools,
     useAtomsDevtools,
    - } from 'jotai/react/devtools';
    + } from 'jotai-devtools';

Other announcements

✨ First announcement

About

A powerful toolkit to enhance your development experience with Jotai

https://jotai.org/

License:MIT License


Languages

Language:TypeScript 98.3%Language:JavaScript 1.6%Language:Shell 0.1%