本文へ移動
cccskills
無料GitHub で公開

react-localstorage-keyboard-nav

Create React components with localStorage persistence and keyboard navigation support

インストール方法を見る

含まれるファイル(2)

  • SKILL.md2.6 KB
  • .skill_id45 B

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

React Components with localStorage Persistence & Keyboard Navigation

This skill guides you through creating reusable React components that:

  1. Persist state to localStorage
  2. Implement keyboard navigation
  3. Follow modal/command palette patterns

Core Pattern

// 1. Define localStorage hooks
const useLocalStorage = (key: string, initialValue: any) => {
  const [value, setValue] = useState(() => {
    const stored = localStorage.getItem(key);
    return stored ? JSON.parse(stored) : initialValue;
  });

  useEffect(() => {
    localStorage.setItem(key, JSON.stringify(value));
  }, [key, value]);

  return [value, setValue];
};

// 2. Implement keyboard navigation
const useKeyboardNav = (items: any[], onSelect: (item: any) => void) => {
  const [selectedIndex, setSelectedIndex] = useState(0);

  const handleKeyDown = (e: KeyboardEvent) => {
    if (e.key === 'ArrowDown') {
      setSelectedIndex(prev => Math.min(prev + 1, items.length - 1));
    } else if (e.key === 'ArrowUp') {
      setSelectedIndex(prev => Math.max(prev - 1, 0));
    } else if (e.key === 'Enter') {
      onSelect(items[selectedIndex]);
    }
  };

  useEffect(() => {
    window.addEventListener('keydown', handleKeyDown);
    return () => window.removeEventListener('keydown', handleKeyDown);
  }, [selectedIndex, items]);

  return { selectedIndex };
};

Implementation Steps

  1. Create Component Scaffolding

    mkdir -p src/components/{Modal,CommandPalette}
    touch src/components/Modal/SettingsModal.tsx
    touch src/components/CommandPalette/CommandPalette.tsx
    
  2. Implement localStorage Persistence

    // SettingsModal.tsx
    const SettingsModal = () => {
      const [settings, setSettings] = useLocalStorage('app-settings', DEFAULT_SETTINGS);
      // ... modal implementation
    };
    
  3. Add Keyboard Navigation

    // CommandPalette.tsx
    const CommandPalette = ({ commands }) => {
      const { selectedIndex } = useKeyboardNav(commands, (cmd) => cmd.action());
      // ... render commands with highlighted selectedIndex
    };
    
  4. Export Components

    // src/components/index.ts
    export * from './Modal/SettingsModal';
    export * from './CommandPalette/CommandPalette';
    

Best Practices

  • Create a settings-keys.ts file to manage localStorage keys
  • Use TypeScript interfaces for settings/commands
  • Implement proper focus management for accessibility

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Incremental audio production with duration mismatch handling, adaptive stem extension, and pre-mix alignment verification

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

Incremental audio production with duration alignment handling, per-stem verification, and adaptive extension strategies

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

Create serverless API proxy endpoints that hide API keys and provide a unified backend for the dashboard frontend. Designed for Vercel deployment.

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

End-to-end audio production workflow with stems, effects, archiving, and verification

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

Handle cascading data retrieval tool failures by falling back to embedded knowledge generation

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

Fallback pattern for executing Python code when execute_code_sandbox fails

日本語の概要は準備中です。原文の説明を表示しています。

HKUDS/OpenSpace7,7552026年8月13日 更新

HKUDS のスキルをすべて見る

このスキルの問題を報告する