Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Keep long-lived external callbacks current
Keep long-lived external callbacks current without recreating their resource unnecessarily; verify commit timing and resource cleanup.
Bad example
| 1 | const editor = useMemo( |
| 2 | () => |
| 3 | createEditor({ |
| 4 | extensions: [ |
| 5 | createExtensions({ onGenerateCaption }), |
| 6 | ], |
| 7 | }), |
| 8 | [], // onGenerateCaption intentionally omitted |
| 9 | ); |
Explanation (EN)
A callback captured once can keep reading obsolete props.
Objašnjenje (HR)
Jednom uhvaćen callback može nastaviti čitati zastarjele propove.
Good example
| 1 | useEffect(() => { |
| 2 | editor.setCaptionHandler(onGenerateCaption); |
| 3 | return () => editor.clearCaptionHandler(onGenerateCaption); |
| 4 | }, [editor, onGenerateCaption]); |
Explanation (EN)
Illustrative SDK contract: update the handler and remove only that registration. Use the actual editor's supported equivalent and verify when it becomes active.
Objašnjenje (HR)
Ilustrativni SDK ugovor ažurira handler i uklanja samo tu registraciju. Koristi podržani ekvivalent stvarnog editora i provjeri kada promjena postaje aktivna.
Notes (EN)
If an external instance must survive callback changes, use its supported update/subscription API or a tested latest-callback bridge with well-defined commit timing.
Bilješke (HR)
Ako vanjska instanca mora preživjeti promjene callbacka, koristi njezin podržani API za ažuriranje ili pretplatu, odnosno provjereni most do najnovijeg callbacka s jasnim trenutkom aktivacije nakon commita.
Exceptions / Tradeoffs (EN)
Do not construct resource-owning editors in useMemo merely to keep them once: React may discard memoized values. A passive-effect ref update can lag a synchronous event; choose an appropriate supported mechanism and clean up the external resource. Effect Events have restricted call sites.