no-use-effect
Fungsinya
Skill ini mengajari agent AI untuk melewati hook useEffect React dan memakai alternatif yang lebih aman. Skill ini ditujukan untuk pengembang React yang menginginkan komponen yang lebih bersih dan lebih mudah di-debug.
Kapan dipakai
- ✓Saat agent akan menulis komponen React baru.
- ✓Saat Anda meninjau kode yang memakai useEffect dan ingin menyederhanakannya.
- ✓Saat agent menambahkan useEffect untuk berjaga-jaga dan Anda ingin itu dihapus.
Link skill
https://github.com/humanlayer/humanlayer/blob/main/.claude/skills/no-use-effect/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
“Refaktor komponen React saya agar tidak memakai useEffect, dan jelaskan setiap penggantinya.”
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Agent mencari tahu apa yang dilakukan setiap effect, lalu memilih salah satu dari lima pengganti, seperti menghitung nilai secara langsung atau memakai penangan event. Ada opsi mount sekali untuk kasus yang jarang.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
No useEffect
Never call useEffect directly. Use derived state, event handlers, data-fetching libraries, or useMountEffect instead.
Quick Reference
This skill is dervied from the React docs: You Might Not Need an Effect. IMPORTANT: when this skill is invoked you MUST read this post in entirety.
| Instead of useEffect for... | Use |
|---|---|
| Deriving state from other state/props | Inline computation (Rule 1) |
| Fetching data | useQuery / data-fetching library (Rule 2) |
| Responding to user actions | Event handlers (Rule 3) |
| One-time external sync on mount | useMountEffect (Rule 4) |
| Resetting state when a prop changes | key prop on parent (Rule 5) |
When to Use This Skill
- Writing new React components
- Refactoring existing
useEffectcalls - Reviewing PRs that introduce
useEffect - An agent adds
useEffect"just in case"
Workflow
1. Identify the useEffect
Determine what the effect is doing -- deriving state, fetching data, responding to an event, syncing with an external system, or resetting state.
2. Apply the Correct Replacement Pattern
Use the five rules below to pick the right replacement.
3. Verify
bun --bun run typecheck -- --filter=<package>
bun --bun run test -- --filter=<package>
The Escape Hatch: useMountEffect
For the rare case where you need to sync with an external system on mount:
The implementation wraps useEffect with an empty dependency array to make intent explicit:
export function useMountEffect(effect: () => void | (() => void)) {
/* eslint-disable no-restricted-syntax */
useEffect(effect, []);
}
Replacement Patterns
Rule 1: Derive state, do not sync it
Most effects that set state from other state are unnecessary and add extra renders.
// BAD: Two render cycles - first stale, then filtered
function ProductList() {
const [products, setProducts] = useState([]);
const [filteredProducts, setFilteredProducts] = useState([]);
useEffect(() => {
setFilteredProducts(products.filter((p) => p.inStock));
}, [products]);
}
// GOOD: Compute inline in one render
function ProductList() {
const [products, setProducts] = useState([]);
const filteredProducts = products.filter((p) => p.inStock);
}
Smell test: You are about to write useEffect(() => setX(deriveFromY(y)), [y]), or you have state that only mirrors other state or props.
Rule 2: Use data-fetching libraries
Effect-based fetching creates race conditions and duplicated caching logic.
// BAD: Race condition risk
function ProductPage({ productId }) {
const [product, setProduct] = useState(null);
useEffect(() => {
fetchProduct(productId).then(setProduct);
}, [productId]);
}
// GOOD: Query library handles cancellation/caching/staleness
function ProductPage({ productId }) {
const { data: product } = useQuery(['product', productId], () =>
fetchProduct(productId)
);
}
Smell test: Your effect does fetch(...) and then setState(...), or you are re-implementing caching, retries, cancellation, or stale handling.
Rule 3: Event handlers, not effects
If a user clicks a button, do the work in the handler.
// BAD: Effect as an action relay
function LikeButton() {
const [liked, setLiked] = useState(false);
useEffect(() => {
if (liked) {
postLike();
setLiked(false);
}
}, [liked]);
return <button onClick={() => setLiked(true)}>Like</button>;
}
// GOOD: Direct event-driven action
function LikeButton() {
return <button onClick={() => postLike()}>Like</button>;
}
Smell test: State is used as a flag so an effect can do the real action, or you are building "set flag -> effect runs -> reset flag" mechanics.
Rule 4: useMountEffect for one-time external sync
Good uses: DOM integration (focus, scroll), third-party widget lifecycles, browser API subscriptions.
// BAD: Guard inside effect
function VideoPlayer({ isLoading }) {
useEffect(() => {
if (!isLoading) playVideo();
}, [isLoading]);
}
// GOOD: Mount only when preconditions are met
function VideoPlayerWrapper({ isLoading }) {
if (isLoading) return <LoadingScreen />;
return <VideoPlayer />;
}
function VideoPlayer() {
useMountEffect(() => playVideo());
}
Use useMountEffect for stable dependencies (singletons, refs, context values that never c
Pertanyaan umum
Apa yang menggantikan useEffect?
Penghitungan langsung, pustaka pengambilan data, penangan event, hook mount sekali, dan prop key untuk mereset status.
Apakah ini melarang useEffect sepenuhnya?
Skill ini menyatakan agar tidak pernah memanggil useEffect secara langsung dan memakai alternatif yang tercantum.
Dari mana saran ini berasal?
Saran ini berdasarkan panduan dokumentasi React tentang kapan sebuah effect tidak diperlukan.
Detail
Deskripsi asli dari pembuat
Enforce the no-useEffect rule when writing or reviewing React code. ACTIVATE when writing React components, refactoring existing useEffect calls, reviewing PRs with useEffect, or when an agent adds useEffect "just in case." Provides the five replacement patterns and the useMountEffect escape hatch.
repo: humanlayer/humanlayer
Popularitas
- Bintang GitHub
- 13k
- Peringkat
- #11389
- Lisensi
- Apache-2.0
- Diperbarui
- 31/10/2026
Komentar
- …
Skill lain dari repositori ini
asd-ste100
13kMengajari agent Anda menulis ulang bahasa Inggris yang membingungkan menjadi kalimat pendek dengan satu makna, yang mudah dibaca oleh orang dan perangkat lunak lain.
better-github-skill
13kMembantu agent Anda memeriksa status pull request, membaca komentar tinjauannya, dan mencari tahu mengapa build CI gagal, dengan skrip GitHub siap pakai.
calldiff
13kMembantu agent Anda membandingkan rantai pemanggilan fungsi dalam basis kode antara dua versi git, sehingga tinjauan kode dapat melihat perilaku apa yang berubah.
chrome-devtools-cli
13kMemungkinkan agent Anda mengendalikan Chrome dari terminal untuk membuka halaman, mengklik, mengisi formulir, dan mengambil cuplikan halaman untuk otomatisasi dan pengujian peramban.
Skill serupa
angular-developer
280kMembantu agent Anda membuat kode Angular dan memberi saran struktur proyek. Berguna saat memulai proyek baru, membuat komponen, atau meningkatkan performa.
frontend-a11y
280kMembantu agent Anda membuat antarmuka web dapat diakses semua orang. Memastikan website dan aplikasi berfungsi baik dengan screen reader dan navigasi keyboard.
frontend-patterns
280kMembuat agent Anda menerapkan pola modern dalam frontend. Mengoptimalkan performa, mengelola state, dan mengikuti praktik terbaik React dan Next.js.