React 19's use() API for reading Promises/Context conditionally. For async data fetching, Suspense, conditional context access, useContext migration.
Teaches React 19's `use()` API for reading Promises (with Suspense) and Context conditionally. Activates when users mention `use()`, async data fetching, Suspense patterns, or migrating from `useContext` for more flexible conditional logic.
/plugin marketplace add djankies/claude-configs/plugin install react-19@claude-configsThis skill is limited to using the following tools:
use() Hook in React 19Teaches when and how to use React 19's new use() API: reads Promises (suspending component) and Context (conditionally—inside if statements, loops, after early returns).
Activates when: User mentions use(), use hook, async patterns, Suspense + data fetching, conditional context, or useContext migration.
| Feature | Hooks | use() |
|---|---|---|
| Conditional calls | ❌ | ✅ |
| After early return | ❌ | ✅ |
| Inside loops | ❌ | ✅ |
| Read Promises | ❌ | ✅ (suspends) |
| Error handling | try-catch | Error Boundary |
Reading Promises:
import { use, Suspense } from 'react';
async function fetchUser(id) {
const res = await fetch(`/api/users/${id}`);
return res.json();
}
function UserProfile({ userId }) {
return (
<Suspense fallback={<div>Loading...</div>}>
<UserData promise={fetchUser(userId)} />
</Suspense>
);
}
function UserData({ promise }) {
const user = use(promise);
return <div>{user.name}</div>;
}
Conditional Context Access:
import { use, createContext } from 'react';
const ThemeContext = createContext('light');
function Button({ isPrimary, children }) {
let className = 'button';
if (isPrimary) {
const theme = use(ThemeContext);
className += ` ${theme}`;
}
return <button className={className}>{children}</button>;
}
Reusable Custom Hook:
import { use, cache } from 'react';
const getUser = cache(async (id) => {
const res = await fetch(`/api/users/${id}`);
return res.json();
});
function useUser(userId) {
if (!userId) return null;
return use(getUser(userId));
}
Async data: Pass Promise as prop from parent → wrap component in Suspense boundary → use use(promise) in child → catch errors with Error Boundary.
Conditional context: Replace useContext(Context) with use(Context) for flexibility across conditional branches, loops, post-early-return.
Migration from useContext: Find useContext(Context) calls → replace with use(Context) → benefits: now conditional if needed.
MUST:
use(promise) in Suspense boundary with fallbackcache() wrapper to prevent duplicate requestsNEVER:
use() inside try-catch blocksuse() outside Component/Hook functionsVerify:
use(promise) with fallbackcache()—stable across rendersFor comprehensive React 19 use() documentation:
research/react-19-comprehensive.md lines 241–311 (use API, Promise Patterns, useContext sections).
This skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.