Code Monkey home page Code Monkey logo

Comments (8)

ZeroX-DG avatar ZeroX-DG commented on June 6, 2024 1

That works great. I spent an hour trying to find out why it's not logging haha.

I think that solved my issue. I'll close this issue. Thank you for the fast respond!

from freya.

marc2332 avatar marc2332 commented on June 6, 2024

That's exactly what use_node/use_node_signal do

from freya.

marc2332 avatar marc2332 commented on June 6, 2024

https://github.com/marc2332/freya/blob/main/examples/min_max_sizing.rs

from freya.

ZeroX-DG avatar ZeroX-DG commented on June 6, 2024

Hmm okay. I was having trouble trying to log out the size of the node inside my use_effect. Turns out it only trigger when you include the size in the rendering code.

fn app() -> Element {
    let (node_ref, size) = use_node_signal();
    use_effect({
        move || {
            println!("{:?}", size().area.width()); // This won't print every time I resize
        }
    });
    rsx!(
        rect {
            width: "50%",
            height: "50%",
            min_width: "200",
            min_height: "100",
            max_width: "300",
            max_height: "250",
            background: "black",
            reference: node_ref,
            label {
                color: "white",
                // "Size: {size().area.width()}x{size().area.height()}"
            }
        }
    )
}
fn app() -> Element {
    let (node_ref, size) = use_node_signal();
    use_effect({
        move || {
            println!("{:?}", size().area.width()); // This will print
        }
    });
    rsx!(
        rect {
            width: "50%",
            height: "50%",
            min_width: "200",
            min_height: "100",
            max_width: "300",
            max_height: "250",
            background: "black",
            reference: node_ref,
            label {
                color: "white",
                "Size: {size().area.width()}x{size().area.height()}"
            }
        }
    )
}

from freya.

marc2332 avatar marc2332 commented on June 6, 2024

Hmm okay. I was having trouble trying to log out the size of the node inside my use_effect. Turns out it only trigger when you include the size in the rendering code.

fn app() -> Element {
    let (node_ref, size) = use_node_signal();
    use_effect({
        move || {
            println!("{:?}", size().area.width()); // This won't print every time I resize
        }
    });
    rsx!(
        rect {
            width: "50%",
            height: "50%",
            min_width: "200",
            min_height: "100",
            max_width: "300",
            max_height: "250",
            background: "black",
            reference: node_ref,
            label {
                color: "white",
                // "Size: {size().area.width()}x{size().area.height()}"
            }
        }
    )
}
fn app() -> Element {
    let (node_ref, size) = use_node_signal();
    use_effect({
        move || {
            println!("{:?}", size().area.width()); // This will print
        }
    });
    rsx!(
        rect {
            width: "50%",
            height: "50%",
            min_width: "200",
            min_height: "100",
            max_width: "300",
            max_height: "250",
            background: "black",
            reference: node_ref,
            label {
                color: "white",
                "Size: {size().area.width()}x{size().area.height()}"
            }
        }
    )
}

That is actually a Dioxus bug I believe

DioxusLabs/dioxus#2347

from freya.

marc2332 avatar marc2332 commented on June 6, 2024

Let me see if I can get around it

from freya.

marc2332 avatar marc2332 commented on June 6, 2024

@ZeroX-DG I can't fix it from Freya but there is a workaround for you I actually use in some places

Use use_memo instead of use_effect

fn app() -> Element {
    let (node_ref, size) = use_node_signal();
    use_memo(move || {
        println!("{:?}", size().area.width());
    });
    rsx!(
        rect {
            width: "50%",
            height: "50%",
            min_width: "200",
            min_height: "100",
            max_width: "300",
            max_height: "250",
            background: "black",
            reference: node_ref,
            label {
                color: "white",
                // "Size: {size().area.width()}x{size().area.height()}"
            }
        }
    )
}

from freya.

marc2332 avatar marc2332 commented on June 6, 2024

Awesome 😄

from freya.

Related Issues (20)

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.