diff --git a/assets/dioxus/docsite_bg.wasm b/assets/dioxus/docsite_bg.wasm index f2bde8bb6..ecdc0b4fd 100644 Binary files a/assets/dioxus/docsite_bg.wasm and b/assets/dioxus/docsite_bg.wasm differ diff --git a/assets/dioxus/snippets/dioxus-interpreter-js-603636eeca72cf05/inline0.js b/assets/dioxus/snippets/dioxus-interpreter-js-603636eeca72cf05/inline0.js index a14ad3184..0161853ba 100644 --- a/assets/dioxus/snippets/dioxus-interpreter-js-603636eeca72cf05/inline0.js +++ b/assets/dioxus/snippets/dioxus-interpreter-js-603636eeca72cf05/inline0.js @@ -163,19 +163,19 @@ let m,p,ls,d,t,op,i,e,z,metaflags; function truthy(val) { return val === "true" || val === true; } - const ns_cache = []; - let ns_cache_tmp1, ns_cache_tmp2; - function get_ns_cache() { - ns_cache_tmp2 = u8buf[u8bufp++]; - if(ns_cache_tmp2 & 128){ - ns_cache_tmp1=s.substring(sp,sp+=u8buf[u8bufp++]); - ns_cache[ns_cache_tmp2&4294967167]=ns_cache_tmp1; - return ns_cache_tmp1; + const attr = []; + let attr_tmp1, attr_tmp2; + function get_attr() { + attr_tmp2 = u8buf[u8bufp++]; + if(attr_tmp2 & 128){ + attr_tmp1=s.substring(sp,sp+=u8buf[u8bufp++]); + attr[attr_tmp2&4294967167]=attr_tmp1; + return attr_tmp1; } else{ - return ns_cache[ns_cache_tmp2&4294967167]; + return attr[attr_tmp2&4294967167]; } - }let u8buf,u8bufp;const evt = []; + }let u32buf,u32bufp;const evt = []; let evt_tmp1, evt_tmp2; function get_evt() { evt_tmp2 = u8buf[u8bufp++]; @@ -187,20 +187,20 @@ let m,p,ls,d,t,op,i,e,z,metaflags; else{ return evt[evt_tmp2&4294967167]; } - }let s = "";let lsp,sp,sl; let c = new TextDecoder();let u32buf,u32bufp;const attr = []; - let attr_tmp1, attr_tmp2; - function get_attr() { - attr_tmp2 = u8buf[u8bufp++]; - if(attr_tmp2 & 128){ - attr_tmp1=s.substring(sp,sp+=u8buf[u8bufp++]); - attr[attr_tmp2&4294967167]=attr_tmp1; - return attr_tmp1; + }const ns_cache = []; + let ns_cache_tmp1, ns_cache_tmp2; + function get_ns_cache() { + ns_cache_tmp2 = u8buf[u8bufp++]; + if(ns_cache_tmp2 & 128){ + ns_cache_tmp1=s.substring(sp,sp+=u8buf[u8bufp++]); + ns_cache[ns_cache_tmp2&4294967167]=ns_cache_tmp1; + return ns_cache_tmp1; } else{ - return attr[attr_tmp2&4294967167]; + return ns_cache[ns_cache_tmp2&4294967167]; } - } - let id,bubbles,value,event_name,field,ns,ptr,len; + }let s = "";let lsp,sp,sl; let c = new TextDecoder();let u8buf,u8bufp; + let len,bubbles,ptr,ns,id,field,value,event_name; export function create(r){ d=r; } @@ -213,10 +213,10 @@ let m,p,ls,d,t,op,i,e,z,metaflags; ls=m.getUint32(d+12*4,true); } p=ls; - if ((metaflags>>>5)&1){ - u8buf=new Uint8Array(m.buffer,m.getUint32(d+5*4,true)) + if ((metaflags>>>3)&1){ + u32buf=new Uint32Array(m.buffer,m.getUint32(d+3*4,true)) } - u8bufp=0;if (metaflags&1){ + u32bufp=0;if (metaflags&1){ lsp = m.getUint32(d+1*4,true); } if ((metaflags>>>2)&1) { @@ -242,10 +242,10 @@ let m,p,ls,d,t,op,i,e,z,metaflags; s = c.decode(new DataView(m.buffer, lsp, sl)); } } - sp=0;if ((metaflags>>>3)&1){ - u32buf=new Uint32Array(m.buffer,m.getUint32(d+3*4,true)) + sp=0;if ((metaflags>>>5)&1){ + u8buf=new Uint8Array(m.buffer,m.getUint32(d+5*4,true)) } - u32bufp=0; + u8bufp=0; for(;;){ op=m.getUint32(p,true); p+=4; diff --git a/learn/0.4/guide/state/index.html b/learn/0.4/guide/state/index.html index 0c229de04..d229feb25 100644 --- a/learn/0.4/guide/state/index.html +++ b/learn/0.4/guide/state/index.html @@ -237,7 +237,7 @@ } -
hello hackernews ()
0 points
by Author
10/10/23 6:18 PM
0 comments
Hover over a story to preview it here

Event Handlers

Next, we need to detect when the user hovers over a section or focuses a link. We can use an event listener to listen for the hover and focus events.

Event handlers are similar to regular attributes, but their name usually starts with on- and they accept closures as values. The closure will be called whenever the event it listens for is triggered. When an event is triggered, information about the event is passed to the closure though the Event structure.

Let's create a onmouseenter event listener in the StoryListing component:

+
hello hackernews ()
0 points
by Author
10/10/23 7:08 PM
0 comments
Hover over a story to preview it here

Event Handlers

Next, we need to detect when the user hovers over a section or focuses a link. We can use an event listener to listen for the hover and focus events.

Event handlers are similar to regular attributes, but their name usually starts with on- and they accept closures as values. The closure will be called whenever the event it listens for is triggered. When an event is triggered, information about the event is passed to the closure though the Event structure.

Let's create a onmouseenter event listener in the StoryListing component:

 cx.render(rsx! {
     div {
         padding: "0.5rem",
@@ -353,7 +353,7 @@
     // New
     match &*preview_state.read() {
 
-
hello hackernews ()
0 points
by Author
10/10/23 6:18 PM
0 comments
Hover over a story to preview it here

You can read more about Hooks in the Hooks reference

The Rules of Hooks

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)
  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

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

No Hooks in Conditionals

+
hello hackernews ()
0 points
by Author
10/10/23 7:08 PM
0 comments
Hover over a story to preview it here

You can read more about Hooks in the Hooks reference

The Rules of Hooks

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)
  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

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

No Hooks in Conditionals

 // ❌ don't call hooks in conditionals!
 // We must ensure that the same hooks will be called every time
 // But `if` statements only run if the conditional is true!
diff --git a/learn/0.4/guide/your_first_component/index.html b/learn/0.4/guide/your_first_component/index.html
index 910d2f45f..44b5777ec 100644
--- a/learn/0.4/guide/your_first_component/index.html
+++ b/learn/0.4/guide/your_first_component/index.html
@@ -153,7 +153,7 @@
     }
 }
 
-
title by author (0) 2023-10-10 18:18:04.226470570 UTC comments

Creating Elements

Next, let's wrap our post description in a div. You can create HTML elements in Dioxus by putting a { after the element name and a } after the last child of the element:

+
title by author (0) 2023-10-10 19:08:07.309649589 UTC comments

Creating Elements

Next, let's wrap our post description in a div. You can create HTML elements in Dioxus by putting a { after the element name and a } after the last child of the element:

 pub fn App(cx: Scope) -> Element {
     let title = "title";
     let by = "author";
@@ -168,7 +168,7 @@
     }
 }
 
-
title by author (0) 2023-10-10 18:18:04.226477670 UTC comments

You can read more about elements in the rsx reference.

Setting Attributes

Next, let's add some padding around our post listing with an attribute.

Attributes (and listeners) modify the behavior or appearance of the element they are attached to. They are specified inside the {} brackets before any children, using the name: value syntax. You can format the text in the attribute as you would with a text node:

+
title by author (0) 2023-10-10 19:08:07.309658689 UTC comments

You can read more about elements in the rsx reference.

Setting Attributes

Next, let's add some padding around our post listing with an attribute.

Attributes (and listeners) modify the behavior or appearance of the element they are attached to. They are specified inside the {} brackets before any children, using the name: value syntax. You can format the text in the attribute as you would with a text node:

 pub fn App(cx: Scope) -> Element {
     let title = "title";
     let by = "author";
@@ -185,7 +185,7 @@
     }
 }
 
-
title by author (0) 2023-10-10 18:18:04.226481870 UTC comments

Note: All attributes defined in dioxus-html follow the snake_case naming convention. They transform their snake_case names to HTML's camelCase attributes.

Note: Styles can be used directly outside of the style: attribute. In the above example, color: "red" is turned into style="color: red".

You can read more about elements in the attribute reference

Creating a Component

Just like you wouldn't want to write a complex program in a single, long, main function, you shouldn't build a complex UI in a single App function. Instead, you should break down the functionality of an app in logical parts called components.

A component is a Rust function, named in UpperCamelCase, that takes a Scope parameter and returns an Element describing the UI it wants to render. In fact, our App function is a component!

Let's pull our story description into a new component:

+
title by author (0) 2023-10-10 19:08:07.309667289 UTC comments

Note: All attributes defined in dioxus-html follow the snake_case naming convention. They transform their snake_case names to HTML's camelCase attributes.

Note: Styles can be used directly outside of the style: attribute. In the above example, color: "red" is turned into style="color: red".

You can read more about elements in the attribute reference

Creating a Component

Just like you wouldn't want to write a complex program in a single, long, main function, you shouldn't build a complex UI in a single App function. Instead, you should break down the functionality of an app in logical parts called components.

A component is a Rust function, named in UpperCamelCase, that takes a Scope parameter and returns an Element describing the UI it wants to render. In fact, our App function is a component!

Let's pull our story description into a new component:

 fn StoryListing(cx: Scope) -> Element {
     let title = "title";
     let by = "author";
@@ -211,7 +211,7 @@
     }
 }
 
-
title by author (0) 2023-10-10 18:18:04.226489170 UTC comments

You can read more about elements in the component reference

Creating Props

Just like you can pass arguments to a function or attributes to an element, you can pass props to a component that customize its behavior!

We can define arguments that components can take when they are rendered (called Props) by adding the #[inline_props] macro before our function definition and adding extra function arguments.

Currently, our StoryListing component always renders the same story. We can modify it to accept a story to render as a prop.

We will also define what a post is and include information for how to transform our post to and from a different format using serde. This will be used with the hackernews API in a later chapter:

+
title by author (0) 2023-10-10 19:08:07.309674189 UTC comments

You can read more about elements in the component reference

Creating Props

Just like you can pass arguments to a function or attributes to an element, you can pass props to a component that customize its behavior!

We can define arguments that components can take when they are rendered (called Props) by adding the #[inline_props] macro before our function definition and adding extra function arguments.

Currently, our StoryListing component always renders the same story. We can modify it to accept a story to render as a prop.

We will also define what a post is and include information for how to transform our post to and from a different format using serde. This will be used with the hackernews API in a later chapter:

 use chrono::{DateTime, Utc};
 use serde::{Deserialize, Serialize};
 
@@ -302,7 +302,7 @@
     }
 }
 
-
hello hackernews by Author (0) 2023-10-10 18:18:04.226493070 UTC 0

You can read more about Props in the Props reference

Cleaning Up Our Interface

Finally, by combining elements and attributes, we can make our post listing much more appealing:

Full code up to this point:

+
hello hackernews by Author (0) 2023-10-10 19:08:07.309678289 UTC 0

You can read more about Props in the Props reference

Cleaning Up Our Interface

Finally, by combining elements and attributes, we can make our post listing much more appealing:

Full code up to this point:

 use dioxus::prelude::*;
 
 // Define the Hackernews types
@@ -443,7 +443,7 @@
     })
 }
 
-
hello hackernews ()
0 points
by Author
10/10/23 6:18 PM
0 comments
+
hello hackernews ()
0 points
by Author
10/10/23 7:08 PM
0 comments