Merge branch 'master' into feat/improved-docs

This commit is contained in:
Marc Espín authored and GitHub committed 2023-06-28 19:21:27 +02:00
commit e413ea4019
76 files changed
+667 -654

No files matched your search

@@ -12,7 +12,7 @@ Suppose we want to build a meme editor. We want to have an input to edit the mem
We start with a `Meme` component, responsible for rendering a meme with a given caption:
```rust
```rust, no_run
{{#include ../../../examples/meme_editor.rs:meme_component}}
```
@@ -20,13 +20,13 @@ We start with a `Meme` component, responsible for rendering a meme with a given
We also create a caption editor, completely decoupled from the meme. The caption editor must not store the caption itself – otherwise, how will we provide it to the `Meme` component? Instead, it should accept the current caption as a prop, as well as an event handler to delegate input events to:
```rust
```rust, no_run
{{#include ../../../examples/meme_editor.rs:caption_editor}}
```
Finally, a third component will render the other two as children. It will be responsible for keeping the state and passing down the relevant props.
```rust
```rust, no_run
{{#include ../../../examples/meme_editor.rs:meme_editor}}
```
@@ -46,19 +46,19 @@ Dioxus offers a better solution than this "prop drilling" – providing context.
First, we have to create a struct for our dark mode configuration:
```rust
```rust, no_run
{{#include ../../../examples/meme_editor_dark_mode.rs:DarkMode_struct}}
```
Now, in a top-level component (like `App`), we can provide the `DarkMode` context to all children components:
```rust
```rust, no_run
{{#include ../../../examples/meme_editor_dark_mode.rs:context_provider}}
```
As a result, any child component of `App` (direct or not), can access the `DarkMode` context.
```rust
```rust, no_run
{{#include ../../../examples/meme_editor_dark_mode.rs:use_context}}
```
@@ -66,6 +66,6 @@ As a result, any child component of `App` (direct or not), can access the `DarkM
For example, here's how we would implement the dark mode toggle, which both reads the context (to determine what color it should render) and writes to it (to toggle dark mode):
```rust
```rust, no_run
{{#include ../../../examples/meme_editor_dark_mode.rs:toggle}}
```