본문으로 건너뛰기
Skillpedia
웹사이트 및 UI (프런트엔드)7.8k · #13078

react-localstorage-keyboard-nav

하는 일

이 스킬은 상태를 기억하고 키보드로 작동하는 React 컴포넌트를 만드는 방법을 보여 줍니다. 메뉴와 명령 팔레트 스타일의 목록을 다룹니다. React 인터페이스를 만드는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓화살표 키와 Enter로 이동할 수 있는 React 메뉴나 목록을 원할 때.
  • ✓페이지를 새로고침한 뒤에도 컴포넌트가 마지막 선택을 기억하기를 원할 때.
  • ✓React로 명령 팔레트나 검색 팝업을 만들고 있을 때.

스킬 링크

https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/react-localstorage-keyboard-nav/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/react-localstorage-keyboard-nav/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“마지막으로 고른 항목을 기억하고 화살표 키로 쓸 수 있는 React 명령 메뉴를 만들어 주실 수 있나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

작은 사용자 정의 도우미가 값을 localStorage에 저장합니다. 다른 도우미는 화살표 키와 Enter를 감지해, 사용자가 목록을 이동하고 항목을 고를 수 있게 합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

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
자주 묻는 질문

특정 React 버전이 필요한가요?

예시는 표준 React 훅을 사용하므로, 대부분의 최신 React 프로젝트에 맞습니다.

상태는 어디에 저장되나요?

같은 기기의 브라우저 localStorage에 저장됩니다.

검색 팝업에 쓸 수 있나요?

네. 스킬은 검색 팝업에 맞는 모달과 명령 팔레트 패턴을 설명합니다.

상세 정보

작성자의 원본 설명

Create React components with localStorage persistence and keyboard navigation support

repo: HKUDS/AgentPilot

인기도

GitHub 스타
7.8k
순위
#13078
라이선스
MIT
업데이트
2026. 11. 1.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬