State is data that records a component’s current condition. In a React list, it includes the displayed entries and current page; changing the page triggers a data fetch and updates the entries. In Yew, state can include both the current page and whether fetching succeeded, failed, or is underway. section 9.4 section 9.5
Component frameworks use state in different ways:
- React uses state hooks and an effect to fetch entries when the page changes. section 9.4
- Yew stores state on the component; create initializes it, update changes it in response to messages, and view renders from it. section 9.5
Listing 9.20 lib.rs: Creating enums for various states
use yew::prelude::*; #1
...
pub enum Msg { #2
IncrementPage,
SetFeedState(FetchState<Feed>),
GetSearch(isize),
}
pub enum FetchState<T> { #3
Fetching,
Success(T),
Failed(reqwest::Error),
}
See a Yew example that represents fetch status as Fetching, Success, or Failed, and defines messages for component actions. section 9.5






































