GithubHelp home page GithubHelp logo

leptos-declarative's People

Contributors

jquesada2016 avatar rakshith-ravi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

leptos-declarative's Issues

Unable to pass `children` into `<PortalProvider>` or `<Portal>`

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.