Skip to content

Commit

Permalink
docs: use_reactive with objects can trigger infinite render loop.
Browse files Browse the repository at this point in the history
Advice use_memo to avoid this.

Closes #472
  • Loading branch information
maartenbreddels committed Feb 28, 2024
1 parent 3e7a5a0 commit 021c2e8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions solara/hooks/use_reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ def use_reactive(
that accept either a reactive variable or a normal value along with an optional `on_change`
callback.
Note that that on each call, if the value changes, the reactive variable will be updated.
For objects that do no implement equality comparison, the will lead to an infinite loop.
In that case, combine the `use_reactive` with `use_memo` to never trigger an update from
the render function.
```python
@solara.component
def Page():
data = solara.use_reactive(solara.use_memo(lambda: MyDataObject()))
...
```
## Arguments:
* value (Union[T, solara.Reactive[T]]): The value of the
Expand Down

0 comments on commit 021c2e8

Please sign in to comment.