Expand description
Function components are a simplified version of normal components.
They consist of a single function annotated with the attribute #[component]
that receives props and determines what should be rendered by returning Html.
Functions with the attribute have to return Html and may take a single parameter for the type
of props the component should accept. The parameter type needs to be a reference to a
Properties type (ex. props: &MyProps). If the function doesn’t have any parameters the
resulting component doesn’t accept any props.
Just mark the component with the attribute. The component will be named after the function.
#[component]
fn HelloWorld() -> Html {
html! { "Hello world" }
}More details about function components and Hooks can be found on Yew Docs
Macros§
- use_
prepared_ state - Use a state prepared on the server side and its value is sent to the client side during hydration.
- use_
transitive_ state - Use a state created as an artifact of the server-side rendering.
Structs§
- Hook
Context - A hook context to be passed to hooks.
- UseForce
Update Handle - A handle which can be used to force a re-render of the associated function component.
- UseReducer
Dispatcher - Dispatcher handle for
use_reduceranduse_reducer_eqhook - UseReducer
Handle - State handle for
use_reduceranduse_reducer_eqhook - UseState
Handle - State handle for the
use_statehook. - UseState
Setter - Setter handle for
use_stateanduse_state_eqhook
Traits§
- Function
Provider - Trait that allows a struct to act as Function Component.
- Hook
- A trait that is implemented on hooks.
- Reducible
- A trait that implements a reducer function of a type.
- Tear
Down - Trait describing the destructor of
use_effecthook.
Functions§
- use_
callback - Get a immutable reference to a memoized
Callback. Its state persists across renders. It will be recreated only if any of the dependencies changes value. - use_
context - Hook for consuming context values in function components.
The context of the type passed as
Tis returned. If there is no such context in scope,Noneis returned. A component which callsuse_contextwill re-render when the data of the context changes. - use_
effect use_effectis used for hooking into the component’s lifecycle and creating side effects.- use_
effect_ with - This hook is similar to
use_effectbut it accepts dependencies. - use_
force_ update - This hook is used to manually force a function component to re-render.
- use_
memo - Get a immutable reference to a memoized value.
- use_
mut_ ref - This hook is used for obtaining a mutable reference to a stateful value. Its state persists across renders.
- use_
node_ ref - This hook is used for obtaining a
NodeRef. It persists across renders. - use_
reducer - This hook is an alternative to
use_state. It is used to handle component’s state and is used when complex actions needs to be performed on said state. - use_
reducer_ eq use_reducerbut only re-renders whenprev_state != next_state.- use_ref
- This hook is used for obtaining a reference to a stateful value. Its state persists across renders.
- use_
state - This hook is used to manage state in a function component.
- use_
state_ eq use_statebut only re-renders whenprev_state != next_state.
Attribute Macros§
- component
- This attribute creates a function component from a normal Rust function.
- function_
component - A re-export of
componentwith the older name. - hook
- This attribute creates a user-defined hook from a normal Rust function.