* Try to add wasi feature to avoid browser's ABI. * Add async render for single-threaded env. * Temporarily enable my own patch branch. It would be modified later after the corresponding library branches are merged. * add example for WASI SSR. * Ready to run WASI on wasmtime. * complete the example * fix fmt * fix fmt * I made a mistake..sry * add yew-router suites for demo * fix typo * Make the async render stream function public * Use target_os instead of feature. * Renew gloo-history's patch. * Exclude WASI example to avoid web-sys. * Try to add CI for WASI example. * Fix CI. * Fix CI that requires compiler 1.67 or newer. * Use CLI's flag instead of exclude example. https://github.com/bytecodealliance/wasmtime/pull/4312 * Remove patchs. * Use LocalServerRenderer instead of ServerRenderer. https://github.com/yewstack/prokio/pull/11#issuecomment-1847979933 * Remove unused exports. * Add description about `LocalServerRenderer`. * fix fmt * fix fmt * Update Cargo.lock * Bump rust compiler's version to 1.67... * Exclude WASI on yew-router browser interfaces. * fix fmt * Wait for gloo's PR dealed. * Rollback to rust compiler 1.64. cc https://github.com/rustwasm/gloo/pull/423#issuecomment-1848353295 * Fix lock file. * Downgrade `toml_datetime` version. * Fix enum for `gloo-history`. * Well, it seems there is no way to avoid the MSRV upgrade.... * fix: Replace feature = "wasi" to target_os = "wasi". * Remove tips for rust version. * Bump `gloo` to 0.11. * Try to test yew-macro on compiler 1.67. * Try to use compiler 1.68 instead. * Try to use compiler 1.69 instead...... * Revert MSRV back * Pin the oldest Cargo.lock. * Downgrade deps for MSRV. * Bump benchmark tool's tokio to 1.35 * Try to write WASI CI. * Rollback the quotes * Combine CI files... * Rollback the use that gloo-history has fixed it. * fix * Bump gloo-history version. * Block raw html update tests on WASI. * Rollback indexmap's version. * fix CI * fix CI * Update some SSR test suites that replace ServerRender instead of LocalServerRender. * Remove yew-router's cfg macro * Fix fmt * Try to fix CI * Update examples/wasi_ssr_module/README.md Co-authored-by: Elina <imelina@elina.website> * Revert back some unnecessary changes. * Clippy * fmt * Fix CI. * Fix CI. * Try to fix clippy. * Fix `ToString` trait. * Remove pin version of WASI CI test. * Pin the newer version. * Fix typo. * Bump `wasm-bindgen`. * Fix SSR example. * Fix typo. * Try to support non-browser environments. * Update wasm-bindgen-test to 0.3.43 refer to rustwasm/wasm-bindgen#4083 * fix doc test running on nightly * Update website/docs/advanced-topics/server-side-rendering.md Co-authored-by: WorldSEnder <WorldSEnder@users.noreply.github.com> * Update WASI CI. * Remove WASI test for rustc 1.76. * Try to let `wasmtime` CLI can be executed. * Limit the function `decode_base64` that it shouldn't runnable in non-browser environment. * Remove WASI example test for rustc 1.76. * Revert changes. * Fix CI * Fix Cargo.lock * Remove unused deps * Undo the formatting changes. * Undo the formatting changes. --------- Co-authored-by: Elina <imelina@elina.website> Co-authored-by: Martin Molzer <WorldSEnder@users.noreply.github.com>
10 KiB
Yew Examples
How to Run
The examples are built with trunk. Once you have the development environment fully set up (see documentation), running an example is as easy as running a single command:
# move into the directory of the example you want to run
# In this case it's the todomvc example
cd examples/todomvc
# build and serve the example
trunk serve --open
Some examples may perform better using the release profile. If something is slow, you can try running it with the --release argument.
We're also publicly hosting the examples at https://examples.yew.rs/<EXAMPLE>.
As an example, check out the TodoMVC example here: https://examples.yew.rs/todomvc
List of Examples
| Example | CT | Description |
|---|---|---|
| async_clock | S | Demonstrates the use of asynchronous tasks in a yew component. |
| boids | S | Yew port of Boids |
| communication_child_to_parent | S | Communication from child to parent components. |
| communication_grandchild_with_grandparent | S | Communication from grandchildren to grandparent components. |
| communication_grandparent_to_grandchild | S | Communication from grandparent to grandchild components. |
| communication_parent_to_child | S | Communication from parent to child components. |
| contexts | F | A technical demonstration of the Context API. |
| counter | S | Simple counter which can be incremented and decremented. |
| counter_functional | F | Simple counter which can be incremented and decremented made using function components. |
| dyn_create_destroy_apps | S | Uses the function Renderer::with_root_and_props and the AppHandle struct to dynamically create and delete Yew apps. |
| file_upload | S | Uses gloo::file to read the content of user uploaded files. |
| function_memory_game | F | Implementation of Memory Game. |
| function_router | F | Identical to router but using function components. |
| function_todomvc | F | Implementation of TodoMVC using function components and hooks. |
| futures | S | Demonstrates how you can use futures and async code with Yew. Features a Markdown renderer. |
| game_of_life | S | Implementation of Conway's Game of Life. |
| immutable | SF | Using immutable types in components. |
| inner_html | S | Embeds an external document as raw HTML by manually managing the element. |
| js_callback | F | Interacts with JavaScript code. |
| keyed_list | S | Demonstrates how to use keys to improve the performance of lists. |
| mount_point | S | Shows how to mount the root component to a custom element. |
| nested_list | S | Renders a styled list which tracks hover events. |
| node_refs | S | Uses a NodeRef to focus the input element under the cursor. |
| password_strength | SF | A password strength estimator implemented in Yew. |
| portals | S | Renders elements into out-of-tree nodes with the help of portals. |
| router | S | The best yew blog built with yew-router. |
| simple_ssr | F | Demonstrates server-side rendering. |
| ssr_router | F | Demonstrates server-side rendering with routing. |
| suspense | F | This is an example that demonstrates <Suspense /> support. |
| timer | S | Demonstrates the use of the interval and timeout services. |
| timer_functional | F | Demonstrates the use of the interval and timeout services using function components |
| todomvc | S | Implementation of TodoMVC. |
| two_apps | S | Runs two separate Yew apps which can communicate with each other. |
| web_worker_fib | F | Calculate Fibonacci numbers in a web worker thread using yew-agent. |
| web_worker_prime | F | Calculate Prime numbers in a web worker thread using yew-agent. |
| webgl | S | Controls a WebGL canvas from Yew. |
| wasi_ssr_module | F | Demonstrates server-side rendering using WASI. |
Next Steps
Have a look at Yew's starter templates when starting a project using Yew – they can significantly simplify things.
Helping Out
If one of the examples catches your interest, look for the "improvements" section in its README.md file.
Most examples list a few ideas for how to improve them.
Consider starting with those but don't hesitate to improve an example in other ways either.
One problem that currently plagues most examples is the lack of styling. Please help us make the examples look as flashy as possible!