๐ช Custom Hooks Development
Welcome to the Custom Hooks tutorial! In this course, you'll learn how to create your own ECC hooks to automate repetitive tasks โ making your development workflow run like a Swiss watch.
We recommend familiarizing yourself with Hooks core concepts first.
๐ฎ Experience the Hook Systemโ
ECC hooks trigger automatically at specific moments. Try these commands to explore different hook types:
๐ Create a Custom Hook from Scratchโ
Let's create a practical custom hook step by step:
Create an auto-format Hook
Step 1 of 5Understand Hook Structure
Every ECC hook consists of 4 core properties: name (identifier), trigger (trigger condition), filePattern (file matching), and command (execution command). Think of it like setting an alarm โ what time (trigger), which days (filePattern), what ringtone (command).
// Hook structure
{
"name": "hook-name", // Unique identifier
"trigger": "edit_file", // When to trigger
"filePattern": "*.{ts,tsx}", // Which files to watch
"command": "npx prettier --write ${file}" // What to execute
}๐ป Write Your Own Hookโ
Write a complete hook configuration in the code playground. Try adding your own rules:
โ Knowledge Checkโ
Which hook type is best suited for 'automatically running Prettier after each file save'?
If a preCommit hook detects console.log, what's the best practice?
What is the key difference between stop hooks and preCommit hooks?
๐ Congratulations!โ
You've completed the Custom Hooks tutorial! You've mastered:
- โ Three hook types: postToolUse, preCommit, stop
- โ Core hook configuration structure
- โ Auto-formatting and type-checking hooks
- โ console.log detection and commit blocking
- โ Session-end audit hooks
๐ Next Stepsโ
- E2E Testing Strategies - Master end-to-end testing
- Hooks Deep Dive - Learn all about hooks