karton-best-practices

Provide performance guidelines for React components consuming Karton state.

6.8k|508|Updated Apr 26, 2025
One-click install
npx skills add https://github.com/stagewise-io/stagewise --skill karton-best-practices
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: karton-best-practices
Source: https://github.com/stagewise-io/stagewise/tree/main/.agents/skills/karton-best-practices
Command: npx skills add https://github.com/stagewise-io/stagewise --skill karton-best-practices

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides essential guidelines and patterns for writing performant React code that interacts with Karton's state management system, preventing unnecessary re-renders and ensuring efficient data consumption.

Core Features & Use Cases

  • Selector Optimization: Learn how to write selectors that leverage Immer's structural sharing and Object.is for efficient re-render prevention.
  • useComparingSelector: Understand when and how to use useComparingSelector with shallow or deep comparators to stabilize references.
  • Derived State Management: Implement best practices for computing derived data using useMemo outside of selectors.
  • Use Case: When developing a complex dashboard that displays real-time agent statuses, applying these best practices ensures that only the components displaying changed data re-render, maintaining a smooth user experience even with frequent state updates.

Quick Start

Use the karton-best-practices skill to understand how to prevent re-renders when selecting nested state.

Frequently Asked Questions about karton-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent unnecessary re-renders when selecting nested state in React?

Prevent unnecessary re-renders by writing selectors that leverage Immer's structural sharing and `Object.is` to ensure components only update when selected state values actually change.

When should I use useComparingSelector instead of standard selectors?

Use `useComparingSelector` with `shallow` or `deep` comparators to stabilize references when standard selectors return new object references on each state update, preventing inefficient derived state computation.

What is the best way to compute derived state from Karton state in React?

Compute derived state using `useMemo` outside of selectors to avoid unnecessary object creation and ensure efficient data consumption within dynamically updating React UIs.

Why does my React component re-render frequently with Karton state updates?

Frequent re-renders occur due to common pitfalls like unnecessary object creation and inefficient derived state computation. Optimize `useKartonState` and `useComparingSelector` hooks to maintain application responsiveness.

Does Karton state management work well for complex real-time dashboards?

Karton state management works well for real-time dashboards by applying selector optimization patterns that ensure only components displaying changed data re-render, maintaining smooth user experiences during frequent state updates.