← Table of Contents · Page 252 of 868
LIFECYCLE HOOKS
Part 6 of 11
HOOKS AS A DESIGN PATTERN
Here are some guidelines for building hooks well.
Keep each hook small and focused on one job.
Make hooks fast, since they run on every action.
Make hooks deterministic when possible, meaning they always give the same answer for the same input, so they are easy to test.
Fail safe: if a hook itself crashes, the usual choice for a safety hook is to block the action instead of allowing it.
Log every hook decision, including blocks, so you can see how often safety rules fire.
And test hooks directly with sample inputs, including malicious ones, just as you would test any other critical code.
Advertisement
Read Aloud:
0:00 / 0:00