Prioritize React performance by avoiding expensive operations and using proper React patterns. Key practices include:
// Good: Hoist React.use detection and create suspend helper
const reactUse = (React as unknown as {use?: (p: Promise<unknown>) => void}).use;
const suspend: (p: Promise<unknown>) => void = reactUse ? reactUse : p => { throw p; };
if (suspendUntil === 'complete' && !view.complete) {
suspend(view.waitForComplete());
}
// Good
init?.(z);
// Avoid
if (init) {
init(z);
}
// Good
<Button onAction={() => setDisplayAllComments(true)}>Older</Button>
// Avoid
<div onClick={() => setDisplayAllComments(true)}>Older</div>
These practices improve both performance and code maintainability while following React best practices.
Enter the URL of a public GitHub repository