-
Notifications
You must be signed in to change notification settings - Fork 188
doc: Add cheat sheet #461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mcmah309
wants to merge
15
commits into
DioxusLabs:main
Choose a base branch
from
mcmah309:managing_state_graph
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
doc: Add cheat sheet #461
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
807df71
doc: Add cheat sheet
mcmah309 403f10f
feat: Add mermaid block component
mcmah309 6fee4ec
feat: Add pan and zoom to mermaid block
mcmah309 bc2a912
fix: Fix markdown body not expanding to full width
mcmah309 29685ca
feat: Remove raw cheat sheet files
mcmah309 1a3e22e
fix: Mermaid break in graph not respected and add height padding
mcmah309 6f5b28d
chore: Update tailwind
mcmah309 7616ee3
doc: Update tailwind generation doc
mcmah309 db3057b
tailwind updates after merge
mcmah309 d115673
Post rebase changes
mcmah309 cbb9176
Change mermaid block cheat sheet into markdown cheat sheet
mcmah309 9781ba6
Re-org cheat sheet
mcmah309 6e4b0ff
Re-org cheat sheet
mcmah309 c25f7da
Merge branch 'main' into managing_state_graph
mcmah309 d9eef4c
Fix route section collisions in cheat sheet
mcmah309 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| # 📘 Cheat Sheet | ||
|
|
||
| ⭐ = Most commonly used hooks | ||
|
|
||
| --- | ||
|
|
||
| ## 🏠 Managing Component State | ||
|
|
||
| *"Which scope does your state or utility belong to?"* | ||
|
|
||
| ### Basic State | ||
|
|
||
| * ⭐ [`use_hook`](https://docs.rs/dioxus/latest/dioxus/prelude/fn.use_hook.html) — Non-reactive, runs on the first use of the hook, which is typically the initial render | ||
| * ⭐ [`use_signal`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_signal.html) — Basic local state, triggers re-renders on write, does not subscribe to other signals | ||
| * [`use_signal_sync`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_signal_sync.html) — Thread-safe signal - Send + Sync | ||
|
|
||
| ### Derived State | ||
|
|
||
| * ⭐ [`use_memo`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_memo.html) — Derived state (memoized), composes signals | ||
| * ⭐ [`use_reactive`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_reactive.html) — Creates a closure (async/sync) to track 'non-reactive' data | ||
| * [`use_set_compare`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_set_compare.html) — Efficient value change tracking | ||
| * [`use_set_compare_equal`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_set_compare_equal.html) — Like `use_set_compare` but uses a custom equality function | ||
|
|
||
| ### Callbacks | ||
|
|
||
| * [`use_callback`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_callback.html) — Keeps a callback up to date for all references to the handle | ||
|
|
||
| --- | ||
|
|
||
| ## 🔄 Sharing Data Between Components | ||
|
|
||
| *"Shared (Context)"* | ||
|
|
||
| ### Context | ||
|
|
||
| * ⭐ [`use_context_provider`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_context_provider.html) — Provides data to any child | ||
| * ⭐ [`use_context`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_context.html) — Consume provided data | ||
| * [`try_use_context`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.try_use_context.html) — Like `use_context` but returns None if missing | ||
| * [`use_root_context`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_root_context.html) — Like `use_context` except creates context at root if missing | ||
| * [`use_coroutine_handle`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_coroutine_handle.html) — Obtain handle to a context-provided coroutine | ||
|
|
||
| ### Context Utilities | ||
|
|
||
| * [`use_clipboard`](https://docs.rs/dioxus-sdk/latest/dioxus_sdk/clipboard/fn.use_clipboard.html) — Access the clipboard (dioxus\_sdk) | ||
| * [`use_window_size`](https://docs.rs/dioxus-sdk/latest/dioxus_sdk/utils/window/fn.use_window_size.html) — Initial window size will be returned with this hook and updated continously as the window is resized (dioxus\_sdk) | ||
| * [`use_geolocation`](https://docs.rs/dioxus-sdk/latest/dioxus_sdk/geolocation/use_geolocation/fn.use_geolocation.html) — Provides the latest geocoordinates. Good for navigation-type apps (dioxus\_sdk) | ||
| * [`use_system_theme`](https://docs.rs/dioxus-sdk/latest/dioxus_sdk/theme/fn.use_system_theme.html) — Initial theme will be returned and updated if the system theme changes (dioxus\_sdk) | ||
|
|
||
| --- | ||
|
|
||
| ## ⚡ Async Operations & Side Effects | ||
|
|
||
| *"When does the code need to run?"* | ||
|
|
||
| ### First Render (Non-Reactive) | ||
|
|
||
| #### Sync | ||
|
|
||
| * ⭐ [`use_hook`](https://docs.rs/dioxus/latest/dioxus/prelude/fn.use_hook.html) — *(already listed)* | ||
| * [`use_hook_with_cleanup`](https://docs.rs/dioxus/latest/dioxus/prelude/fn.use_hook_with_cleanup.html) — Use a hook with a cleanup function that runs when component is dropped | ||
| * ⭐ [`use_debounce`](https://docs.rs/dioxus-sdk/latest/dioxus_sdk/utils/timing/fn.use_debounce.html) — Calls a function only after provided duration has passed (dioxus\_sdk) | ||
| * [`use_interval`](https://docs.rs/dioxus-sdk/latest/dioxus_sdk/utils/timing/fn.use_interval.html) — Repeatedly calls a function every certain period (dioxus\_sdk) | ||
| * [`use_server_cached`](https://docs.rs/dioxus/latest/dioxus/prelude/fn.use_server_cached.html) — Runs a function on the server (or client if server is not enabled) and sends result to client. Caches the value on the client | ||
|
|
||
| #### Async | ||
|
|
||
| * [`use_channel`](https://docs.rs/dioxus-sdk/latest/dioxus_sdk/utils/channel/fn.use_channel.html), [`use_listen_channel`](https://docs.rs/dioxus-sdk/latest/dioxus_sdk/utils/channel/fn.use_listen_channel.html) — Create and listen to channels for communication between components (dioxus\_sdk) | ||
|
|
||
| ### Before Every Subsequent Render | ||
|
|
||
| * [`use_before_render`](https://docs.rs/dioxus/latest/dioxus/prelude/fn.use_before_render.html) — Register a function to run before every subsequent render | ||
|
|
||
| ### Render Phase (While Component Is Alive) | ||
|
|
||
| #### Sync | ||
|
|
||
| * [`use_callback`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_callback.html) — *(already listed)* | ||
| * [`use_signal`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_signal.html) — *(already listed)* | ||
| * [`use_signal_sync`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_signal_sync.html) — *(already listed)* | ||
| * [`use_memo`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_memo.html) — *(already listed)* | ||
| * [`use_set_compare`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_set_compare.html) — *(already listed)* | ||
| * [`use_set_compare_equal`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_set_compare_equal.html) — *(already listed)* | ||
|
|
||
| #### Sync & Async | ||
|
|
||
| * [`use_reactive`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_reactive.html) — *(already listed)* | ||
|
|
||
| #### Async | ||
|
|
||
| * ⭐ [`use_future`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_future.html) — Run an async task once | ||
| * [`use_coroutine`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_coroutine.html) — Stream-based concurrency through channels | ||
| * ⭐ [`use_resource`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_resource.html) — Async derived state | ||
| * [`use_server_future`](https://docs.rs/dioxus-fullstack/latest/dioxus_fullstack/prelude/fn.use_server_future.html) — Async derived state that runs on the server and caches on the client | ||
|
|
||
| ### Post Renders | ||
|
|
||
| * ⭐ [`use_effect`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_effect.html) — Side effects after render, composes signals | ||
| * [`use_hook_did_run`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_hook_did_run.html) — Lifecycle check if this hook has been called on the latest render | ||
| * [`use_after_render`](https://docs.rs/dioxus/latest/dioxus/prelude/fn.use_after_render.html) — Push a function to be run after the next render | ||
|
|
||
| ### Cleanup | ||
|
|
||
| * [`use_drop`](https://docs.rs/dioxus/latest/dioxus/prelude/fn.use_drop.html) — Callback invoked when component is dropped | ||
|
|
||
| --- | ||
|
|
||
| ## 💾 Persisting Data | ||
|
|
||
| *"Persistent (Storage)"* | ||
|
|
||
| ### Local Storage | ||
|
|
||
| * ⭐ [`use_persistent`](https://docs.rs/dioxus-sdk/latest/dioxus_sdk/storage/fn.use_persistent.html) — Store data across application reloads as either local storage or a file storage (dioxus\_sdk) | ||
| * [`use_storage`](https://docs.rs/dioxus-sdk/latest/dioxus_sdk/storage/fn.use_storage.html) — Like `use_persistent` except the storage location is generic, which may be useful for custom implementations (dioxus\_sdk) | ||
| * [`use_singleton_persistent`](https://docs.rs/dioxus-sdk/latest/dioxus_sdk/storage/fn.use_singleton_persistent.html) — Persistent storage shared for calls from same line (dioxus\_sdk) | ||
| * [`use_storage_entry`](https://docs.rs/dioxus-sdk/latest/dioxus_sdk/storage/fn.use_storage_entry.html) — Creates a `StorageEntry` with latest value from storage or init if does not exist (dioxus\_sdk) | ||
|
|
||
| ### Synced Storage | ||
|
|
||
| * [`use_synced_storage`](https://docs.rs/dioxus-sdk/latest/dioxus_sdk/storage/fn.use_synced_storage.html) — Store data that persists and syncs across all app sessions (dioxus\_sdk) | ||
| * [`use_synced_storage_entry`](https://docs.rs/dioxus-sdk/latest/dioxus_sdk/storage/fn.use_synced_storage_entry.html) — Creates a `StorageEntry` with updates subscription (dioxus\_sdk) | ||
|
|
||
| --- | ||
|
|
||
| ## 🌐 Global State | ||
|
|
||
| *"Global (Truly app-wide)"* | ||
|
|
||
| * [`GlobalSignal`](https://docs.rs/dioxus/latest/dioxus/prelude/type.GlobalSignal.html) — Global signal (sync) | ||
| * [`GlobalMemo`](https://docs.rs/dioxus/latest/dioxus/prelude/type.GlobalMemo.html) — Derived global state (sync) | ||
| * [`Global`](https://docs.rs/dioxus/latest/dioxus/prelude/struct.Global.html) — A lazy value that is created once per application (sync) | ||
|
|
||
| --- | ||
|
|
||
| ## 🧭 Navigation & Routing | ||
|
|
||
| *"Route-based"* | ||
|
|
||
| ### Core Routing | ||
|
|
||
| * ⭐ [`Routable`](https://docs.rs/dioxus/latest/dioxus/prelude/trait.Routable.html) — The `dioxus-router` macro used for routing | ||
| * ⭐ [`use_route`](https://docs.rs/dioxus-router/latest/dioxus_router/hooks/fn.use_route.html) — Access information about the current routing location | ||
| * ⭐ [`use_navigator`](https://docs.rs/dioxus-router/latest/dioxus_router/hooks/fn.use_navigator.html) — Access navigator to change router history | ||
|
|
||
| ### Nested Routes | ||
|
|
||
| * [`use_outlet_context`](https://docs.rs/dioxus-router/latest/dioxus_router/hooks/fn.use_outlet_context.html) — Access to the outlet context for the route nesting level |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| .mermaid { | ||
| position: relative; | ||
| width: 100%; | ||
| overflow: hidden; | ||
| border: 1px solid #ddd; | ||
| margin: 20px 0px; | ||
| cursor: grab; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,6 +157,51 @@ pub fn CodeBlock(contents: String, name: Option<String>) -> Element { | |
| } | ||
| } | ||
|
|
||
| #[component] | ||
| pub fn MermaidBlock(chart: &'static str) -> Element { | ||
| rsx! { | ||
| div { | ||
| document::Link { rel: "stylesheet", href: asset!("assets/mermaid_block.css") } | ||
| div { | ||
| class: "mermaid min-h-[60vh]", | ||
| style: "background-color: #fff; ", | ||
| "value": "{chart}", | ||
| } | ||
| script { r#type: "module", | ||
| r#" | ||
mcmah309 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/+esm'; | ||
| import Panzoom from 'https://cdn.jsdelivr.net/npm/@panzoom/[email protected]/+esm'; | ||
|
|
||
| mermaid.initialize({{ | ||
| startOnLoad: false, | ||
| }}); | ||
|
|
||
| const mermaidElements = document.querySelectorAll('.mermaid'); | ||
| let elements = []; | ||
| mermaidElements.forEach((element, index) => {{ | ||
| if (element.getAttribute('data-processed') === 'true') {{ | ||
| return; | ||
| }} | ||
| element.textContent = element.value; | ||
mcmah309 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| elements.push(element); | ||
| }}); | ||
|
|
||
| mermaid.run().then(() => {{ | ||
| elements.forEach((element, index) => {{ | ||
mcmah309 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let svg = element.firstElementChild; | ||
| const panzoom = Panzoom(svg, {{ | ||
| step: 1, | ||
| maxScale: 10, | ||
| minScale: 0.5, | ||
| }}); | ||
| element.addEventListener('wheel', panzoom.zoomWithWheel); | ||
| }}) | ||
| }});"# | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub(crate) static Copy: Component<()> = |_| { | ||
| rsx!( | ||
| svg { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.