no-use-effect
Fungsinya
Panduan ini mengarahkan agen Anda menjauh dari pola React yang umum dan sering menyebabkan bug serta render tambahan. Ditujukan untuk pengembang yang menulis atau meninjau komponen dan hook React.
Kapan dipakai
- ✓Saat agen Anda membuat komponen atau hook React baru.
- ✓Saat ia merefaktor pemanggilan useEffect yang ada.
- ✓Saat sebuah pull request menambahkan useEffect yang ingin Anda tinjau.
Link skill
https://github.com/fastrepl/anarlog/blob/main/.agents/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
“Tinjau komponen React ini dan hapus useEffect apa pun yang sebenarnya tidak diperlukan.”
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Skill pertama-tama menanyakan alasan setiap effect ada, lalu menggantinya dengan pola paling sederhana yang sesuai. Pola itu mencakup menghitung nilai saat render, memakai library data untuk pengambilan data, menangani aksi pengguna di event handler, dan hook sempit untuk pengaturan satu kali yang benar-benar diperlukan.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
No useEffect
Never call useEffect directly unless the work is a true mount-only sync with an external system and no simpler pattern fits. Prefer a render-time computation, a query or mutation hook, an event handler, or a remount boundary instead.
Workflow
- Classify why the effect exists.
- Replace it with the narrowest pattern below.
- Verify with the project's normal lint, typecheck, and tests.
Replacement Patterns
1. Derive state, do not sync it
Replace useEffect(() => setX(derive(y)), [y]) with inline computation or the project's existing memoization conventions.
const filteredProducts = products.filter((product) => product.inStock);
Smell test: state only mirrors props or other state.
2. Use query or mutation libraries for async work
Replace fetch-in-effect code with the app's data layer.
const productQuery = useQuery({
queryKey: ["product", productId],
queryFn: () => fetchProduct(productId),
});
Smell test: the effect fetches, awaits, retries, cancels, or writes async results into local state.
3. Use event handlers for user actions
Do the work where the action happens instead of setting a flag and reacting later.
const handleLike = () => {
postLike();
};
Smell test: state exists only to trigger an effect, then gets reset.
4. Use useMountEffect for mount-only external sync
Use this only for work that is naturally "set up on mount, clean up on unmount": DOM integration, subscriptions, third-party widgets, and stable singleton bindings.
If the project already has a useMountEffect, use it. If not, add a small wrapper:
import { useEffect } from "react";
export function useMountEffect(effect: () => void | (() => void)) {
useEffect(effect, []);
}
Prefer changing component structure so the component only mounts once preconditions are satisfied.
Smell test: the effect is a one-time setup or teardown for something outside React.
5. Use key to reset component state
If a component should behave like a fresh instance when an ID or entity changes, remount it from the parent.
return <VideoPlayer key={videoId} videoId={videoId} />;
Smell test: the effect exists only to reset local state when props change.
Review Standard
Treat new direct useEffect usage as a bug by default. Ask which of the five patterns applies. Accept direct useEffect only with explicit justification that the code is a mount-only external sync and that useMountEffect is the intended escape hatch.
Structure React Code This Way
Order component logic like this:
- Hooks that read external state or data.
- Local state.
- Derived values computed during render.
- Event handlers.
- Early returns.
- Render output.
Do not introduce mirrored state just to make an effect possible.
Pertanyaan umum
Kapan useEffect masih diizinkan?
Hanya untuk sinkronisasi nyata dengan sistem luar yang berjalan sekali saat mount, dan hanya jika tidak ada pola yang lebih sederhana.
Apakah ini mengubah perilaku aplikasi saya?
Tujuannya menjaga perilaku tetap sama, dan panduan meminta Anda menjalankan pemeriksaan lint, tipe, dan tes normal setelahnya.
Apa itu nilai turunan?
Nilai yang dihitung dari nilai lain saat render, alih-alih disalin ke variabel state terpisah.
Detail
Deskripsi asli dari pembuat
Avoid direct React `useEffect` usage when writing or reviewing React components and hooks. Use this skill when creating new React code, refactoring existing `useEffect` calls, reviewing PRs that introduce `useEffect`, or when an agent reaches for `useEffect` as a default. Replace effects with derived state, query or mutation libraries, event handlers, `useMountEffect` for mount-only external sync, or `key`-based remounts.
repo: fastrepl/anarlog
Popularitas
- Bintang GitHub
- 9.7k
- Peringkat
- #12213
- Lisensi
- MIT
- Diperbarui
- 1/11/2026
Komentar
- …
Skill lain dari repositori ini
sqlite-schema-design
9.7kMembantu agent Anda mendesain atau meninjau tabel basis data yang disinkronkan di antara perangkat dengan SQLite Sync, mengikuti aturannya untuk kunci, nilai default, dan perubahan skema.
anarlog
9.7kMembantu agent Anda mencari catatan rapat, ringkasan, transkrip, peserta, dan item tindak lanjut Anarlog Anda, atau mengimpor rekaman lokal.
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.