jquesada2016 / leptos-declarative Goto Github PK
View Code? Open in Web Editor NEWDeclarative components for the leptos rust web framework.
Declarative components for the leptos rust web framework.
Don't see any documentation on that
Here's a demo of not being able to pass children into <PortalProvider>
:
use leptos::*;
use leptos_declarative::prelude::*;
pub fn main() {
mount_to_body(|cx| {
view! { cx,
<Providers>
<div>"My app."</div>
</Providers>
}
})
}
#[component]
pub fn Providers(cx: Scope, children: Children) -> impl IntoView {
view! { cx, <PortalProvider>{children(cx)}</PortalProvider> }
}
The above code raises the following error:
1 error[E0507]: cannot move out of `children`, a captured variable in an `Fn` closure
--> src/main.rs:16:5
|
15 | pub fn Providers(cx: Scope, children: Children) -> impl IntoView {
| -------- captured outer variable
16 | view! { cx, <PortalProvider>{children(cx)}</PortalProvider> }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------^^^^^^^^^^^^^^^^^^^^^^^^
| | |
| | variable moved due to use in closure
| | move occurs because `children` has type `Box<dyn FnOnce(leptos::Scope) -> Fragment>`, which does not implement the `Copy` trait
| captured by this `Fn` closure
| `children` is moved here
|
And here's an example of not being able to pass children into <Portal>
:
use leptos::*;
use leptos_declarative::prelude::*;
struct MyPortalId;
pub fn main() {
mount_to_body(|cx| {
view! { cx,
<PortalProvider>
<PortalOutput id=MyPortalId/>
<MyPortal>
<p>"I went through the portal!"</p>
</MyPortal>
</PortalProvider>
};
})
}
#[component]
pub fn MyPortal(cx: Scope, children: Children) -> impl IntoView {
view! { cx,
<Portal id=MyPortalId>
{children(cx)}
</Portal>
}
}
The above code raises the following error:
1 error[E0507]: cannot move out of `children`, a captured variable in an `Fn` closure
--> src/main.rs:21:5
|
20 | pub fn MyPortal(cx: Scope, children: Children) -> impl IntoView {
| -------- captured outer variable
21 | / view! { cx,
22 | | <Portal id=MyPortalId>
23 | | {children(cx)}
| | --------
| | |
| | variable moved due to use in closure
| | move occurs because `children` has type `Box<dyn FnOnce(leptos::Scope) -> Fragment>`, which does not implement the `Copy` trait
24 | | </Portal>
25 | | }
| | ^
| | |
| |_____captured by this `Fn` closure
| `children` is moved here
|
I think these errors might be related to the fact that portal.rs
uses:
type Children = Box<dyn Fn(Scope) -> Fragment>;
Whereas leptos::Children
is of type Box<dyn FnOnce(Scope) -> Fragment>
(which usesFnOnce
instead of Fn
), however, I'm new to Rust, so I don't fully understand these error messages yet.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.