Loading...
Loading...
React 19 patterns and React Compiler behavior with Context shorthand syntax and use() hook. Use when working with Context, useContext, use() hook, Provider components, optimization patterns like useMemo, useCallback, memo, memoization, or when the user mentions React 19, React Compiler, Context.Provider, or manual optimization.
npx skill4agent add qingqishi/shiqingqi.com react19-patterns<MyContext value={someValue}>
<ChildComponents />
</MyContext><MyContext.Provider value={someValue}>
<ChildComponents />
</MyContext.Provider>use()useContext()use()import { use } from "react";
import { MyContext } from "./MyContext";
function MyComponent() {
const value = use(MyContext);
return <div>{value}</div>;
}import { useContext } from "react";
import { MyContext } from "./MyContext";
function MyComponent() {
const value = useContext(MyContext);
return <div>{value}</div>;
}function MyComponent({ items }) {
// React Compiler automatically memoizes this computation
const filteredItems = items.filter((item) => item.active);
// React Compiler automatically stabilizes this function reference
const handleClick = (id) => {
console.log(id);
};
return (
<div>
{filteredItems.map((item) => (
<button key={item.id} onClick={() => handleClick(item.id)}>
{item.name}
</button>
))}
</div>
);
}import { useMemo, useCallback, memo } from "react";
function MyComponent({ items }) {
// ❌ Don't use useMemo - React Compiler handles this
const filteredItems = useMemo(
() => items.filter((item) => item.active),
[items],
);
// ❌ Don't use useCallback - React Compiler handles this
const handleClick = useCallback((id) => {
console.log(id);
}, []);
return <div>...</div>;
}
// ❌ Don't use memo() - React Compiler handles this
export default memo(MyComponent);<ViewTransition>A tree hydrated but some attributes of the server rendered HTML didn't match the client properties.
This won't be patched up. This can happen if a SSR-ed Client Component used...
Specifically: style={{view-transition-name:"_T_0_"}}view-transition-name<ViewTransition>
<Suspense fallback={<HeaderSkeleton />}>
<Header />
</Suspense>
<Suspense fallback={null}>{children}</Suspense>
</ViewTransition><ViewTransition>
<Suspense fallback={<HeaderSkeleton />}>
<Header />
</Suspense>
{children} {/* NOT in Suspense - causes hydration error! */}
</ViewTransition><Suspense fallback={<LoadingSkeleton />}>
<ViewTransition>
<Header />
{children}
</ViewTransition>
</Suspense><Context value={...}><Context.Provider value={...}>use(Context)useContext(Context)