Spitha – A React Component Booster

Overview

EEG Neural Wearable System Diagram
Figure 1: Example Implementation of Spitha with ChakraUI

Spitha is a performance-enhancing wrapper component for React and Next.js, written in TypeScript. It optimizes component rendering using an internal system of memoization, batched updates, and asynchronous lazy rendering. The component is designed to integrate seamlessly into any modern React project and supports native ChakraUI styling.

Traditional React components tend to re-render unnecessarily, especially in complex UI trees with state-heavy children or repeated API calls. This affects performance in data-intensive applications such as dashboards or graph-based UIs. Spitha was designed to address this bottleneck by intelligently controlling when and how components render and refresh — without requiring manual memoization or architectural overhauls.

Role

Key Features

Memoization + Callback Retention

To prevent function re-creation across renders, Spitha uses:

const stableCallback = useCallback(() => { ... }, []);

This ensures downstream child components do not re-render unnecessarily due to new references, preserving render time and keeping React’s reconciliation tree shallow.

Asynchronous Lazy Loading

When the user scrolls past a Spitha-wrapped component, it triggers background API fetching using a custom intersection observer and asynchronous logic. This ensures network activity occurs during user inactivity:

if (isOutOfView && !loading) {
  fetchData().then(setData);
}

Batching & Trigger Thresholds

React’s native event batching is extended in Spitha with a `threshold` prop, which defines the scroll distance from the component before re-render is allowed. For instance:

<Spitha threshold={0.4}> <MyComponent /> </Spitha>

This avoids unproductive re-renders from edge-case viewport events.

Framework & Styling Agnostic

Spitha is built to support both raw HTML/CSS and framework-level styling systems like ChakraUI. All `style` and `children` props are passed through without mutation.

Architecture & Implementation

Spitha is architected as a composable performance optimization wrapper in React. It is implemented as a single top-level functional component that leverages internal React hooks to track visibility, throttle fetches, and memoize rendered subtrees. Each responsibility—render suppression, async deferral, style pass-through—is modularized for testability and extensibility.

EEG Neural Wearable System Diagram
Figure 2: Performance Metrics

Hook-Level Breakdown

Render Cycle Optimization

The React reconciliation process compares virtual DOM trees to determine updates. In traditional React apps, prop changes—even non-functional ones—can trigger deep child re-renders. Spitha prevents this through:

Additionally, render branches are internally profiled to ensure minimal time between component visibility and paint.

Why This Works

React’s rendering performance is often dictated not just by raw JSX complexity, but by when updates occur. Spitha defers updates until necessary, and ensures fetch logic happens during idle periods. This produces:

Next.js Launch Integration

The launch page for Spitha is written in Next.js using ChakraUI. Spitha components are wrapped around hero images, feature sections, and testimonial tiles. Chakra's system for layout tokens and spacing props ensures style consistency while Spitha ensures update efficiency. This demonstrates real-world compatibility in a marketing-grade UI context.

TypeScript Engineering

Spitha is typed using advanced TypeScript generics to maintain full intellisense and prop inference. The fetch signature is defined as:

type SpithaProps = {
  fetchData: () => Promise<any>;
  initialData?: any[];
  threshold?: number;
  children?: React.ReactNode;
  style?: React.CSSProperties;
}

This allows Spitha to be dropped into any React component tree without additional type configuration.

Style Propagation Engine

To support Chakra, Tailwind, and inline CSS, Spitha passes down all style props and other DOM attributes untouched. This is done by destructuring and forwarding props to the child render tree:

return (
  <div ref={observerRef} style={props.style}>
    {props.children}
  </div>
);

This ensures Spitha is transparent from a visual and developer standpoint—components wrapped by Spitha behave and appear exactly as they would otherwise.

Memory Considerations

Each instance of Spitha retains its own fetch state, observer registration, and memoization boundary. This localizes memory use and ensures GC eligibility when unmounted. React’s fiber architecture guarantees cleanup of all attached effects, keeping Spitha safe for heavy dynamic lists or route transitions.

Performance Testing & Results

Spitha’s performance was rigorously benchmarked using jest within a controlled React environment. The tests compared:

Test Methodology

To run the tests:

yarn jest

During the tests, rendering times were captured and output as markdown using this snippet:

const markdown = [
  '# Rendering Times for Native Data of Normal Components vs Spitha',
  '| Component | Time (milliseconds) |',
  '|-----------|---------------------|'
];
renderingData.forEach((data) => {
  markdown.push(`| ${data.normalRenderingTime} | ${data.myComponentRenderingTime} |`);
});
fs.writeFileSync('NEW_FILE_NAME.md', markdown.join('\n'));

The results demonstrated a consistent rendering performance improvement of approximately 40% across all benchmarked components.

Challenges

Future Work

Tools Used