Jotai state management patterns — atoms, globalAtom, contextAtom, and persistence.
70
86%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
packages/kit-bg/src/states/jotai/atoms/globalAtom and EAtomNames for standardizationsettings.ts, account.ts, hardware.ts, currency.tspackages/kit/src/states/jotai/contexts/[feature_name]/atoms.tscontextAtom from createJotaiContext for consistencycontexts/
├── marketV2/
│ ├── atoms.ts - State definitions
│ ├── actions.ts - State operations
│ └── index.ts - Exports
├── swap/
│ ├── atoms.ts
│ ├── actions.ts
│ └── index.tspackages/kit/src/views/globalAtom and contextAtom patterns without architectural justificationpackages/kit-bg/src/states/jotai/atoms/packages/kit/src/states/jotai/contexts/[name]/atoms.tsIMPORTANT: These are the ONLY two atom patterns used in the project. Do not create custom atom patterns or use plain Jotai atoms outside of these established structures.
// packages/kit-bg/src/states/jotai/atoms/myFeature.ts
import { globalAtom } from '../utils';
import { EAtomNames } from '../atomNames';
export const myFeatureAtom = globalAtom<MyFeatureState>({
name: EAtomNames.myFeature,
initialValue: { /* initial state */ },
persist: true, // if persistence needed
});// packages/kit/src/states/jotai/contexts/myFeature/atoms.ts
import { createJotaiContext } from '../../utils';
const { contextAtom, useContextAtom } = createJotaiContext();
export const myFeatureDataAtom = contextAtom<MyData | null>(null);
// Export hook for components
export { useContextAtom };import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import { myFeatureAtom } from '@onekeyhq/kit-bg/src/states/jotai/atoms';
function MyComponent() {
// Read and write
const [value, setValue] = useAtom(myFeatureAtom);
// Read only
const value = useAtomValue(myFeatureAtom);
// Write only
const setValue = useSetAtom(myFeatureAtom);
}d71e6b7
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.