1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! This module contains hooks that can be used to add behavior to components.
//!
//! Hooks are implemented as traits which extend the [`Hooks`](crate::Hooks) object that gets passed to your component.
//!
//! For example, if you want to create a hook that acts as a shorthand for getting the user's
//! username from context, you might define and use it like this:
//!
//! ```
//! # use iocraft::prelude::*;
//! # struct UserInfo { name: String }
//! pub trait UseUserInfo {
//! /// Returns the user's username.
//! fn use_username(&mut self) -> String;
//! }
//!
//! impl UseUserInfo for Hooks<'_, '_> {
//! fn use_username(&mut self) -> String {
//! self.use_context::<UserInfo>().name.to_string()
//! }
//! }
//!
//! #[component]
//! fn Greeting(mut hooks: Hooks) -> impl Into<AnyElement<'static>> {
//! let username = hooks.use_username();
//! element! {
//! Text(content: format!("Hello, {}!", username))
//! }
//! }
//! ```
//!
//! # Rules of Hooks
//!
//! Usage of hooks is subject to the same sorts of rules as [React hooks](https://react.dev/reference/rules/rules-of-hooks).
//!
//! They must be called in the same order every time, so calling them in any sort of conditional or
//! loop is not allowed. If you break the rules of hooks, you can expect a panic.
//!
//! # Note to Library Authors
//!
//! If you are writing a library that provides hooks, it's recommended that you seal your hook
//! traits so you can add new methods without breaking semver compatibility.
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;