react-localstorage-keyboard-nav
What it does
This skill shows how to create React components that remember their state and work with the keyboard. It covers menus and command palette style lists. It is for developers building React interfaces.
When to use it
- ✓When you want a React menu or list that can be used with arrow keys and Enter.
- ✓When you want a component to remember a choice after the page reloads.
- ✓When you are building a command palette or a search popup in React.
Skill link
https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/react-localstorage-keyboard-nav/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“Can you make a React command menu I can use with arrow keys that remembers my last choice?”
5 new skills a week. 1 minute to read.
How it works
A small custom helper saves values in local storage. Another helper listens for arrow keys and Enter, so the user can move through the list and pick an item.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
React Components with localStorage Persistence & Keyboard Navigation
This skill guides you through creating reusable React components that:
- Persist state to localStorage
- Implement keyboard navigation
- 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
Create Component Scaffolding
mkdir -p src/components/{Modal,CommandPalette} touch src/components/Modal/SettingsModal.tsx touch src/components/CommandPalette/CommandPalette.tsxImplement localStorage Persistence
// SettingsModal.tsx const SettingsModal = () => { const [settings, setSettings] = useLocalStorage('app-settings', DEFAULT_SETTINGS); // ... modal implementation };Add Keyboard Navigation
// CommandPalette.tsx const CommandPalette = ({ commands }) => { const { selectedIndex } = useKeyboardNav(commands, (cmd) => cmd.action()); // ... render commands with highlighted selectedIndex };Export Components
// src/components/index.ts export * from './Modal/SettingsModal'; export * from './CommandPalette/CommandPalette';
Best Practices
- Create a
settings-keys.tsfile to manage localStorage keys - Use TypeScript interfaces for settings/commands
- Implement proper focus management for accessibility
FAQ
Does it need a specific React version?
The examples use standard React hooks, so they fit most modern React projects.
Where is the state saved?
It is saved in the browser's local storage on the same device.
Can I use it for a search popup?
Yes. The skill describes modal and command palette patterns that fit a search popup.
Details
Original description by the author
Create React components with localStorage persistence and keyboard navigation support
repo: HKUDS/AgentPilot
Popularity
- GitHub stars
- 7.8k
- Ranking position
- #13078
- License
- MIT
- Updated
- 11/1/2026
Comments
- …
More skills from this repository
agentpilot
7.8kHelps your agent improve a project step by step by preparing a task and running the AgentPilot loop that proposes, tests and scores changes.
openspace
7.8kHelps your agent set up OpenSpace, a tool that stores and fetches agent skills, and connect it to your AI app through MCP.
rsi-arena
7.8kHelps your agent set up and run standard AI benchmark tests, such as AIME and Terminal-Bench, to compare different improvement methods.
experiment-guide
7.8kHelps your agent plan small experiments, read their results and record findings while it investigates how to improve a program.
Similar skills
angular-developer
280kHelps your agent create Angular code and give project structure advice. Useful for starting new projects, creating code parts, or improving performance and accessibility.
frontend-a11y
280kHelps your agent make web interfaces accessible to everyone. It ensures websites and apps work well with screen readers and keyboard navigation.
frontend-patterns
280kHas your agent apply modern patterns in frontend development. It optimizes performance, manages state, and follows best practices in React and Next.js.