Skip to content

Commit 6778959

Browse files
committed
misc docs fixes
1 parent b19bed8 commit 6778959

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

docs/examples/python/django_router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ def my_component():
1515
route("/router/string/<str:value>/", html.div("Example 6")),
1616
route("/router/uuid/<uuid:value>/", html.div("Example 7")),
1717
route("/router/two_values/<int:value>/<str:value2>/", html.div("Example 8")),
18-
route("/router/*", html.div("Fallback")),
18+
route("/router/<any:value>", html.div("Fallback")),
1919
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from channels.db import database_sync_to_async
2+
from reactpy import component, html
3+
4+
from example.models import TodoItem
5+
from reactpy_django.hooks import use_query
6+
7+
8+
async def get_items():
9+
return await database_sync_to_async(TodoItem.objects.all)()
10+
11+
12+
@component
13+
def todo_list():
14+
item_query = use_query(get_items)
15+
16+
if item_query.loading:
17+
rendered_items = html.h2("Loading...")
18+
elif item_query.error or not item_query.data:
19+
rendered_items = html.h2("Error when loading!")
20+
else:
21+
rendered_items = html.ul([html.li(item.text, key=item.pk) for item in item_query.data])
22+
23+
def on_click(event):
24+
item_query.refetch()
25+
26+
return html.div("Rendered items: ", rendered_items, html.button({"onClick": on_click}, "Refresh"))

docs/src/reference/hooks.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,16 @@ Query functions can be sync or async.
135135

136136
{% include-markdown "../../includes/orm.md" start="<!--orm-excp-start-->" end="<!--orm-excp-end-->" %}
137137

138-
??? question "Can I make a failed query try again?"
138+
??? question "Can I force a query to run again?"
139139

140-
Yes, `#!python use_mutation` can be re-executed by calling `#!python reset()` on your `#!python use_mutation` instance.
140+
`#!python use_query` can be re-executed by calling `#!python refetch()` on your `#!python use_query` result.
141141

142-
For example, take a look at `#!python reset_event` below.
142+
The example below uses an `#!python onClick` event to determine when to reset the query.
143143

144144
=== "components.py"
145145

146146
```python
147-
{% include "../../examples/python/use_mutation_reset.py" %}
148-
```
149-
150-
=== "models.py"
151-
152-
```python
153-
{% include "../../examples/python/todo_item_model.py" %}
147+
{% include "../../examples/python/use_query_refetch.py" %}
154148
```
155149

156150
??? question "Why does the example query function return `#!python TodoItem.objects.all()`?"
@@ -231,9 +225,9 @@ Mutation functions can be sync or async.
231225

232226
{% include-markdown "../../includes/orm.md" start="<!--orm-excp-start-->" end="<!--orm-excp-end-->" %}
233227

234-
??? question "Can I make a failed mutation try again?"
228+
??? question "Can I force a mutation run again?"
235229

236-
Yes, `#!python use_mutation` can be re-executed by calling `#!python reset()` on your `#!python use_mutation` instance.
230+
`#!python use_mutation` can be re-executed by calling `#!python reset()` on your `#!python use_mutation` result.
237231

238232
For example, take a look at `#!python reset_event` below.
239233

@@ -251,7 +245,7 @@ Mutation functions can be sync or async.
251245

252246
??? question "Can `#!python use_mutation` trigger a refetch of `#!python use_query`?"
253247

254-
Yes, `#!python use_mutation` can queue a refetch of a `#!python use_query` via the `#!python refetch=...` argument.
248+
`#!python use_mutation` can queue a refetch of a `#!python use_query` via the `#!python refetch=...` argument.
255249

256250
The example below is a merge of the `#!python use_query` and `#!python use_mutation` examples above with the addition of a `#!python use_mutation(refetch=...)` argument.
257251

docs/src/reference/router.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ URL router that enables the ability to conditionally render other components bas
2525
You can duplicate all your URL patterns within both Django and ReactPy, but it's easiest to use a wildcard `.*` within Django's `#!python urlpatterns` and let ReactPy handle the rest. For example...
2626

2727
```python linenums="0"
28-
urlpatterns = [
29-
re_path(r"^.*$", my_reactpy_router_view),
30-
]
28+
urlpatterns = [ re_path(r"^.*$", my_reactpy_router_view) ]
3129
```
3230

3331
=== "components.py"

0 commit comments

Comments
 (0)