Skip to content

Commit 4b3c142

Browse files
committed
[docs] Update event-handler sub faq
1 parent c00035e commit 4b3c142

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

docs/FAQs/UseASubscriptionInAnEventHandler.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ How do I access the value of a subscription from within an event handler?
1111
## The Root Problem
1212

1313
Subscriptions are stateful. That said, they offer a 90% solution where you don't have to worry about their state.
14-
But this comes with a caveat: **the only safe place to call `subscribe` is within a reagent component function.**
14+
But this comes with a caveat: **the only safe place to call `subscribe` is within a reagent render function.**
1515

1616
!!! Note
1717
See [Flows - Reactive Context](/re-frame/flows-advanced-topics/#reactive-context)
1818
for an in-depth explanation.
1919

2020
### DOM event handlers
2121

22-
Inner functions, such as DOM event handlers, don't count. Consider this component:
22+
Callback functions, such as DOM event handlers, don't count. Consider this component:
2323

2424
```clj
2525
(defn my-btn []
2626
[:button {:on-click #(subscribe [:some (gensym)])}])
2727
```
2828

29-
Our `:on-click` function isn't actually called when the component renders. Instead, we've given the function to the browser, expecting it to get called later. The problem is, reagent and re-frame have no way to safely manage your subscription at that time. The result is a memory leak. If the browser calls your `:on-click` a thousand times, re-frame will "create" a thousand unique subscriptions, and there's no code in place to "dispose" them later.
29+
Our `:on-click` function isn't actually called when the component renders. Instead, we've given the function to the browser, expecting it to get called later. The problem is, reagent and re-frame have no way to safely manage your subscription at that time. The result is a memory leak. If the browser calls your `:on-click` a thousand times, re-frame may "create" a thousand unique subscriptions, and there's no code in place to "dispose" them later.
3030

3131
### Re-frame event handlers
3232

@@ -46,7 +46,7 @@ Calling `subscribe` inside an event handler goes against re-frame's design, whic
4646

4747
### Incidental safety
4848

49-
Calling `subscribe` *outside* a component is somewhat safe, as long as you've also called it *inside* a component.
49+
Calling `subscribe` *outside* a render-fn is somewhat safe, as long as you've also called it *inside* a render-fn.
5050
The *outside* one has no way to dispose, but the *inside* one might dispose later.
5151

5252
Of course, that requires your component to be around while your other code runs.

0 commit comments

Comments
 (0)