Back to Yew

Yew Examples

examples/README.md

0.18.010.8 KB
Original Source

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:

bash
# 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 using the rand crate require a special rust flag to be enabled:

bash
RUSTFLAGS='--cfg getrandom_backend="wasm_js"' 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

ExampleCTDescription
async_clockSDemonstrates the use of asynchronous tasks in a yew component.
boidsSYew port of Boids
communication_child_to_parentSCommunication from child to parent components.
communication_grandchild_with_grandparentSCommunication from grandchildren to grandparent components.
communication_grandparent_to_grandchildSCommunication from grandparent to grandchild components.
communication_parent_to_childSCommunication from parent to child components.
contextsFA technical demonstration of the Context API.
counterSSimple counter which can be incremented and decremented.
counter_functionalFSimple counter which can be incremented and decremented made using function components.
dyn_create_destroy_appsSUses the function Renderer::with_root_and_props and the AppHandle struct to dynamically create and delete Yew apps.
file_uploadSUses gloo::file to read the content of user uploaded files.
function_delayed_inputFDemonstrates how to implement a form with delayed input processing.
function_memory_gameFImplementation of Memory Game.
function_routerFIdentical to router but using function components.
function_todomvcFImplementation of TodoMVC using function components and hooks.
futuresSDemonstrates how you can use futures and async code with Yew. Features a Markdown renderer.
game_of_lifeSImplementation of Conway's Game of Life.
immutableSFUsing immutable types in components.
inner_htmlSEmbeds an external document as raw HTML by manually managing the element.
js_callbackFInteracts with JavaScript code.
keyed_listSDemonstrates how to use keys to improve the performance of lists.
mount_pointSShows how to mount the root component to a custom element.
nested_listSRenders a styled list which tracks hover events.
node_refsSUses a NodeRef to focus the input element under the cursor.
password_strengthSFA password strength estimator implemented in Yew.
portalsSRenders elements into out-of-tree nodes with the help of portals.
routerSThe best yew blog built with yew-router.
simple_ssrFDemonstrates server-side rendering.
ssr_routerFDemonstrates server-side rendering with routing.
suspenseFThis is an example that demonstrates <Suspense /> support.
timerSDemonstrates the use of the interval and timeout services.
timer_functionalFDemonstrates the use of the interval and timeout services using function components
todomvcSImplementation of TodoMVC.
two_appsSRuns two separate Yew apps which can communicate with each other.
web_worker_fibFCalculate Fibonacci numbers in a web worker thread using yew-agent.
web_worker_primeFCalculate Prime numbers in a web worker thread using yew-agent.
webglSControls a WebGL canvas from Yew.
wasi_ssr_moduleFDemonstrates 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!