You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `view!` macros in Leptos is often the largest part of a component, and can get extremely long when writing complex components. This macro aims to be as **concise** as possible, trying to **minimise unnecessary punctuation/words** and **shorten common patterns**.
112
112
113
-
## Performance note
114
-
115
-
Currently, the macro expands to the [builder syntax](https://github.com/leptos-rs/leptos/blob/main/docs/book/src/view/builder.md) (ish), but it has some [performance downsides](https://github.com/leptos-rs/leptos/issues/1492#issuecomment-1664675672) in SSR mode. This is expected to be fixed with the new renderer in Leptos `0.7`, so I'm not going to make this implementation.
116
-
117
113
## Compatibility
118
114
119
115
This macro will be compatible with the latest stable release of Leptos. The macro references Leptos items using `::leptos::...`, no items are re-exported from this crate. Therefore, this crate will likely work with any Leptos version if no view-related items are changed.
@@ -125,6 +121,9 @@ The below are the versions with which I have tested it to be working. It is like
125
121
|`0.1`|`0.5`|
126
122
|`0.2`|`0.5`, `0.6`|
127
123
|`0.3`|`0.6`|
124
+
|`0.4`|`0.7`|
125
+
126
+
This crate also has a feature `"nightly"` that enables better proc-macro diagnostics (simply enables the nightly feature in proc-macro-error2. Necessary while [this pr](https://github.com/GnomedDev/proc-macro-error-2/pull/5) is not yet merged).
128
127
129
128
## Syntax details
130
129
@@ -182,7 +181,7 @@ The name of the parameter in the component function must be the same as the slot
182
181
183
182
Using the slots defined by the [`SlotIf` example linked](https://github.com/leptos-rs/leptos/blob/main/examples/slots/src/lib.rs):
184
183
```rust
185
-
useleptos::*;
184
+
useleptos::prelude::*;
186
185
useleptos_mview::mview;
187
186
188
187
#[component]
@@ -219,7 +218,7 @@ There are (currently) 3 main types of values you can pass in:
219
218
input
220
219
class="main"
221
220
checked=true
222
-
madeup=3
221
+
data-index=3
223
222
type={input_type}
224
223
on:input={move|_|handle_input(1)};
225
224
}
@@ -343,60 +342,6 @@ mview! {
343
342
344
343
Note that the `use:` directive automatically calls `.into()` on its argument, consistent with behaviour from Leptos.
345
344
346
-
#### Special Attributes
347
-
348
-
There are a few special attributes you can put on your component to emulate some features only available on HTML elements.
349
-
350
-
If a component has a `class` attribute, the classes using the selector syntax `.some-class` and dynamic classes `class:thing={signal}` can be passed in!
351
-
352
-
```rust
353
-
#[component]
354
-
// the `class` parameter should have these attributes and type to work properly
// "my-component" will always be present, extra classes passed in will also be added
358
-
div.my-componentclass=[class.get()] { "..." }
359
-
}
360
-
}
361
-
362
-
// <div class="my-component extra-class">
363
-
mview! {
364
-
TakesClasses.extra-class;
365
-
};
366
-
```
367
-
368
-
It is suggested to only pass in static classes (i.e. with selectors or just a plain `class="..."`), as using dynamic classes needs to construct a new string every time any of the signals change; dynamic classes are supported if you want them though.
This is also supported on slots by having a `class` and `id` field with the same attributes and types as the components above.
399
-
400
345
### Children
401
346
402
347
You may have noticed that the `let:data` prop was missing from the previous section on directive attributes!
@@ -405,7 +350,7 @@ This is replaced with a closure right before the children block. This way, you c
405
350
```rust
406
351
mview! {
407
352
Await
408
-
future=[async { 3 }]
353
+
future={async { 3 }}
409
354
|monkeys| {
410
355
p { {*monkeys} " little monkeys, jumping on the bed." }
411
356
}
@@ -425,7 +370,7 @@ mview! {
425
370
426
371
Summary from the previous section on values in case you missed it: children can be literal strings (not bools or numbers!), blocks with Rust code inside (`{*monkeys}`), or the closure shorthand `[number() + 1]`.
427
372
428
-
Children with closures are also supported on slots, add a field `children: Callback<T, View>` to use it (`T` is whatever type you want).
373
+
Children with closures are also supported on slots.
429
374
430
375
## Extra details
431
376
@@ -454,7 +399,6 @@ If an attribute shorthand has hyphens:
0 commit comments