eden/contrib/reviewstack/src/jotai/README.md
This directory contains Jotai atoms for the ReviewStack application.
The app uses Jotai for React state management. All state is defined in atoms.ts and exported through index.ts.
primerColorModeAtom - User's color mode preference (day/night)gitHubTokenPersistenceAtom, gitHubTokenStateAtom, gitHubHostnameAtom, gitHubUsernameAtom - Authentication with cross-tab logout supportgitHubClientAtom - Cached GitHub API clientgitHubPullRequestAtom, gitHubPullRequestForParamsAtom - PR data and loadinggitHubPullRequestVersionsAtom, gitHubPullRequestSelectedVersionIndexAtom - PR version historygitHubDiffCommitIDsAtom, gitHubPullRequestVersionDiffAtom - Diff computationgitHubPullRequestReviewThreadsAtom, gitHubThreadsForDiffFileAtom - Review commentsstackedPullRequestAtom, stackedPullRequestFragmentsAtom - PR stack supportdiffServiceClient.ts)Heavy computation runs in a SharedWorker:
diffAndTokenizeAtom - Tokenizes and diffs file contentscolorMapAtom - TextMate color maps for syntax highlightinglineRangeAtom - Fetches line ranges for expanding collapsed sectionslineToPositionAtom - Line to position mapping for commentsimport {useAtom, useAtomValue, useSetAtom} from 'jotai';
import {gitHubPullRequestAtom, primerColorModeAtom} from './jotai';
// Read-only
const pullRequest = useAtomValue(gitHubPullRequestAtom);
// Read and write
const [colorMode, setColorMode] = useAtom(primerColorModeAtom);
// Write-only
const setColorMode = useSetAtom(primerColorModeAtom);
For async atoms where you want to avoid Suspense:
import {useAtomValue} from 'jotai';
import {loadable} from 'jotai/utils';
import {useMemo} from 'react';
function MyComponent() {
const loadableAtom = useMemo(() => loadable(asyncAtom), []);
const result = useAtomValue(loadableAtom);
if (result.state === 'loading') {
return <Spinner />;
}
if (result.state === 'hasError') {
return <Error error={result.error} />;
}
return <div>{result.data}</div>;
}
| Hook | Purpose |
|---|---|
useAtom(atom) | Read and write an atom |
useAtomValue(atom) | Read-only access to an atom |
useSetAtom(atom) | Write-only access to an atom |
useStore() | Access the Jotai store directly |
| Utility | Purpose |
|---|---|
atom() | Create a primitive or derived atom |
atomFamily() | Create parameterized atoms (from jotai-family) |
atomWithStorage() | Create an atom with localStorage persistence |
loadable() | Wrap async atom to get loading/error/data states |