Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the hook rules more consistent #302

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs-src/0.5/en/guide/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ DemoFrame {

Hooks are a powerful way to manage state in Dioxus, but there are some rules you need to follow to insure they work as expected. Dioxus uses the order you call hooks to differentiate between hooks. Because the order you call hooks matters, you must follow these rules:

1. Hooks may be only used in components or other hooks (we'll get to that later)
1. Hooks may be only used in components or other hooks (we'll get to that later).
2. On every call to the component function
1. The same hooks must be called
2. In the same order
3. Hooks name's should start with `use_` so you don't accidentally confuse them with regular functions
1. the same hooks must be called (except in the case of early returns, as explained later in the [Error Handling chapter](../../cookbook/error_handling.md))
2. in the same order.
3. Hooks name's should start with `use_` so you don't accidentally confuse them with regular functions (`use_signal()`, `use_signal()`, `use_resource()`, etc...).

These rules mean that there are certain things you can't do with hooks:

Expand Down
9 changes: 4 additions & 5 deletions docs-src/0.5/en/reference/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ But how can Dioxus differentiate between multiple hooks in the same component? A
This is only possible because the two hooks are always called in the same order, so Dioxus knows which is which. Because the order you call hooks matters, you must follow certain rules when using hooks:

1. Hooks may be only used in components or other hooks (we'll get to that later).
2. On every call to a component function.
3. The same hooks must be called (except in the case of early returns, as explained later in the [Error Handling chapter](../../cookbook/error_handling.md)).
4. In the same order.
5. Hook names should start with `use_` so you don't accidentally confuse them with regular
functions (`use_signal()`, `use_signal()`, `use_resource()`, etc...).
2. On every call to the component function
1. the same hooks must be called (except in the case of early returns, as explained later in the [Error Handling chapter](../../cookbook/error_handling.md))
2. in the same order.
3. Hook names should start with `use_` so you don't accidentally confuse them with regular functions (`use_signal()`, `use_signal()`, `use_resource()`, etc...).

These rules mean that there are certain things you can't do with hooks:

Expand Down