Sorry—due to formatting limitations I’ll describe succinctly:
Scope
Official: strictly limited to being called inside its own effect. ESLint rule enforces this.
User hook: free‑form – can be passed around as props,stored in state or passed to third‑party SDKs.
Safety
Official version comes with linting protection and guaranteed never to leak stale data inside effects.
User hook places responsibility entirely on developer – misuse can silently break dependencies if called outside allowed context.
When both exist
Inside your own component’s effects -> prefer official hook .
When sharing callbacks across component boundaries or libraries -> fall back to user hook .
#实际使用模式示例
⏳ 场景一:Memoized 行组件接收稳定点击回调
"Example code"
Ok I realize we lost formatting again due complexity…Given constraints I'll provide simplified snippet examples rar than full tables.
再看场景二。WebSocket 消息处理
简洁版的观点是,tsx
function PriceFeed {
const =uSstate;const handleMsg=@reActUs/e/@sevent=>{
let next=parseInt;setPrice,if notify;/* always fresh threshold*/
});uEsEfect=>{
let ws=new WebSocket;ws.addEvnetListener;return=>ws.close;},),/* only reconnect when symbol changes */
• \U201C\uSevent<\/bkdkd>\ returns a reference that never changes while keeping inner closure always fresh — solving both problems thrown at us by ordinary hooks.
• The trick is just one ref updated via layout-effect + one one-time memoised wrapper.
• Callbacks meant for events/timers/subscriptions → \U201C\uSevent<\/bkdkd>\ . Do NOT invoke m during rendering.
• For pure calculations performed during rendering → \U201C\uScallback<\/bkdkd>\ .
• In React ≥18 re’s also \U201C\uUseffectevent<\/bkdkd>\ : safe inside effects only with lint support.
• Check wher library already offers hooks like \U201C\uUseinterval<\/bkdkd>。\U201C\uUsetimeout<\/bkdkd>,etc.;y already encapsulate this pattern.
• Keep dev warnings active—passing non-functions triggers console errors early.
• Remember two rules above!They keep your components predictable under concurrent updates.