wip: more examples
This commit is contained in:
1 parent
904b26f711
commit
11f89e5d33
27 files changed
+64
-57
No files matched your search
@@ -15,7 +15,7 @@ fn main() {
|
||||
}
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
let (state, set_state) = use_state(&cx, || 0);
|
||||
let (state, set_state) = use_state_classic(&cx, || 0);
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
section { class: "py-12 px-4 text-center"
|
||||
|
||||
@@ -27,9 +27,9 @@ enum Operator {
|
||||
}
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
let (cur_val, set_cur_val) = use_state(&cx, || 0.0_f64);
|
||||
let (operator, set_operator) = use_state(&cx, || None as Option<Operator>);
|
||||
let (display_value, set_display_value) = use_state(&cx, || "0".to_string());
|
||||
let (cur_val, set_cur_val) = use_state_classic(&cx, || 0.0_f64);
|
||||
let (operator, set_operator) = use_state_classic(&cx, || None as Option<Operator>);
|
||||
let (display_value, set_display_value) = use_state_classic(&cx, || "0".to_string());
|
||||
|
||||
let clear_display = display_value.eq("0");
|
||||
let clear_text = if clear_display { "C" } else { "AC" };
|
||||
|
||||
@@ -11,7 +11,7 @@ fn main() {
|
||||
}
|
||||
|
||||
fn CustomA(cx: Context<()>) -> VNode {
|
||||
let (val, set_val) = use_state(&cx, || "abcdef".to_string() as String);
|
||||
let (val, set_val) = use_state_classic(&cx, || "abcdef".to_string() as String);
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
|
||||
@@ -9,7 +9,7 @@ fn main() {
|
||||
}
|
||||
|
||||
fn App(cx: Context<()>) -> VNode {
|
||||
let cansee = use_state_new(&cx, || false);
|
||||
let cansee = use_state(&cx, || false);
|
||||
rsx! { in cx,
|
||||
div {
|
||||
"Shadow of the child:"
|
||||
|
||||
@@ -24,8 +24,8 @@ fn main() {
|
||||
type RowList = im_rc::HashMap<usize, Rc<str>, nohash_hasher::BuildNoHashHasher<usize>>;
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
let (items, set_items) = use_state(&cx, || RowList::default());
|
||||
let (selection, set_selection) = use_state(&cx, || None as Option<usize>);
|
||||
let (items, set_items) = use_state_classic(&cx, || RowList::default());
|
||||
let (selection, set_selection) = use_state_classic(&cx, || None as Option<usize>);
|
||||
|
||||
let create_rendered_rows = move |from, num| move |_| set_items(create_row_list(from, num));
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ fn main() {
|
||||
|
||||
// this is a component
|
||||
static Example: FC<()> = |cx| {
|
||||
let (event, set_event) = use_state(&cx, || None);
|
||||
let (event, set_event) = use_state_classic(&cx, || None);
|
||||
|
||||
let handler = move |evt| {
|
||||
set_event(Some(evt));
|
||||
|
||||
@@ -11,7 +11,7 @@ fn main() {
|
||||
}
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
let (val, set_val) = use_state(&cx, || "asd".to_string());
|
||||
let (val, set_val) = use_state_classic(&cx, || "asd".to_string());
|
||||
|
||||
cx.render(rsx! {
|
||||
div { class: "max-w-lg max-w-xs bg-blue-800 shadow-2xl rounded-lg mx-auto text-center py-12 mt-4 rounded-xl"
|
||||
@@ -49,7 +49,7 @@ static Example: FC<()> = |cx| {
|
||||
};
|
||||
|
||||
static UserInput: FC<()> = |cx| {
|
||||
let (val, set_val) = use_state(&cx, || "asd".to_string());
|
||||
let (val, set_val) = use_state_classic(&cx, || "asd".to_string());
|
||||
|
||||
rsx! { in cx,
|
||||
div { class: "mb-4"
|
||||
|
||||
@@ -10,7 +10,7 @@ fn main() {
|
||||
}
|
||||
|
||||
static Example: FC<()> = |cx| {
|
||||
let (name, set_name) = use_state(&cx, || "...?");
|
||||
let (name, set_name) = use_state_classic(&cx, || "...?");
|
||||
|
||||
log::debug!("Running component....");
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ fn main() {
|
||||
}
|
||||
|
||||
static Example: FC<()> = |cx| {
|
||||
let (name, set_name) = use_state(&cx, || "...?");
|
||||
let (name, set_name) = use_state_classic(&cx, || "...?");
|
||||
cx.render(rsx! {
|
||||
section { class: "py-12 px-4 text-center"
|
||||
div { class: "w-full max-w-2xl mx-auto"
|
||||
|
||||
@@ -13,7 +13,7 @@ fn main() {
|
||||
}
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
let (contents, set_contents) = use_state(&cx, || "asd");
|
||||
let (contents, set_contents) = use_state_classic(&cx, || "asd");
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
|
||||
@@ -14,7 +14,7 @@ fn main() {
|
||||
}
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
let (contents, set_contents) = use_state(&cx, || "asd");
|
||||
let (contents, set_contents) = use_state_classic(&cx, || "asd");
|
||||
|
||||
cx.render(rsx! {
|
||||
div { class: "flex items-center justify-center flex-col"
|
||||
|
||||
@@ -26,9 +26,9 @@ pub struct TodoItem {
|
||||
}
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
let (draft, set_draft) = use_state(&cx, || "".to_string());
|
||||
let (filter, set_filter) = use_state(&cx, || FilterState::All);
|
||||
let todos = use_state_new(&cx, || BTreeMap::<uuid::Uuid, TodoItem>::new());
|
||||
let (draft, set_draft) = use_state_classic(&cx, || "".to_string());
|
||||
let (filter, set_filter) = use_state_classic(&cx, || FilterState::All);
|
||||
let todos = use_state(&cx, || BTreeMap::<uuid::Uuid, TodoItem>::new());
|
||||
cx.render(rsx!(
|
||||
div {
|
||||
id: "app"
|
||||
|
||||
@@ -26,7 +26,7 @@ struct ExampleProps {
|
||||
}
|
||||
|
||||
static Example: FC<ExampleProps> = |cx| {
|
||||
let name = use_state_new(&cx, move || cx.initial_name);
|
||||
let name = use_state(&cx, move || cx.initial_name);
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
|
||||
@@ -25,9 +25,9 @@ pub struct TodoItem {
|
||||
}
|
||||
|
||||
pub fn App(cx: Context<()>) -> VNode {
|
||||
let (draft, set_draft) = use_state(&cx, || "".to_string());
|
||||
let (todos, set_todos) = use_state(&cx, || HashMap::<uuid::Uuid, Rc<TodoItem>>::new());
|
||||
let (filter, set_filter) = use_state(&cx, || FilterState::All);
|
||||
let (draft, set_draft) = use_state_classic(&cx, || "".to_string());
|
||||
let (todos, set_todos) = use_state_classic(&cx, || HashMap::<uuid::Uuid, Rc<TodoItem>>::new());
|
||||
let (filter, set_filter) = use_state_classic(&cx, || FilterState::All);
|
||||
|
||||
let filtered_todos = todos.iter().filter(move |(id, item)| match filter {
|
||||
FilterState::All => true,
|
||||
@@ -99,7 +99,7 @@ pub struct TodoEntryProps {
|
||||
}
|
||||
|
||||
pub fn TodoEntry(cx: Context<TodoEntryProps>) -> VNode {
|
||||
let (is_editing, set_is_editing) = use_state(&cx, || false);
|
||||
let (is_editing, set_is_editing) = use_state_classic(&cx, || false);
|
||||
let contents = "";
|
||||
let todo = TodoItem {
|
||||
checked: false,
|
||||
|
||||
@@ -53,9 +53,9 @@ pub fn App(cx: Context<()>) -> VNode {
|
||||
}
|
||||
|
||||
pub fn TodoList(cx: Context<()>) -> VNode {
|
||||
let (draft, set_draft) = use_state(&cx, || "".to_string());
|
||||
let (todos, set_todos) = use_state(&cx, || HashMap::<uuid::Uuid, Rc<TodoItem>>::new());
|
||||
let (filter, set_filter) = use_state(&cx, || FilterState::All);
|
||||
let (draft, set_draft) = use_state_classic(&cx, || "".to_string());
|
||||
let (todos, set_todos) = use_state_classic(&cx, || HashMap::<uuid::Uuid, Rc<TodoItem>>::new());
|
||||
let (filter, set_filter) = use_state_classic(&cx, || FilterState::All);
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
@@ -102,7 +102,7 @@ pub struct TodoEntryProps {
|
||||
}
|
||||
|
||||
pub fn TodoEntry(cx: Context<TodoEntryProps>) -> VNode {
|
||||
let (is_editing, set_is_editing) = use_state(&cx, || false);
|
||||
let (is_editing, set_is_editing) = use_state_classic(&cx, || false);
|
||||
let contents = "";
|
||||
let todo = TodoItem {
|
||||
checked: false,
|
||||
|
||||
@@ -74,7 +74,7 @@ impl TodoManager {
|
||||
}
|
||||
|
||||
pub fn TodoList(cx: Context<()>) -> VNode {
|
||||
let draft = use_state_new(&cx, || "".to_string());
|
||||
let draft = use_state(&cx, || "".to_string());
|
||||
let todos = use_read(&cx, &TODO_LIST);
|
||||
let filter = use_read(&cx, &FILTER);
|
||||
|
||||
@@ -118,7 +118,7 @@ pub struct TodoEntryProps {
|
||||
}
|
||||
|
||||
pub fn TodoEntry(cx: Context, props: &TodoEntryProps) -> VNode {
|
||||
let (is_editing, set_is_editing) = use_state(&cx, || false);
|
||||
let (is_editing, set_is_editing) = use_state_classic(&cx, || false);
|
||||
let todo = use_read(&cx, &TODO_LIST).get(&cx.id).unwrap();
|
||||
|
||||
cx.render(rsx! (
|
||||
|
||||
Reference in new issue
Block a user