Skip to content
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

Resize Watcher getting error when I try to use @login_required method on local_auth example #2606

Open
kumaraguru1735 opened this issue Feb 14, 2024 · 3 comments

Comments

@kumaraguru1735
Copy link
Contributor

I am getting below error

image

@masenf
Copy link
Collaborator

masenf commented Feb 15, 2024

The problem here is that event triggers inside an rx.cond do not get memoized, and need to be formatted explicitly.

Here is some similar repro code:

import reflex as rx

class State(rx.State):
    v: str = ""
    n: int = 0
    show: bool = True

class FunnyButton(rx.button.__self__):
    def _get_hooks(self):
        on_click = self.event_triggers.get('on_click')
        if isinstance(on_click, rx.EventChain):
            on_click = rx.utils.format.format_prop(on_click)
        return f"const foo = '%s'" % on_click

def index() -> rx.Component:
    return rx.fragment(
        FunnyButton.create(State.n.to_string(), on_click=State.set_n(State.n + 1)),
        rx.cond(
            State.show,
            FunnyButton.create(State.n.to_string(), on_click=State.set_n(State.n + 1)),
            rx.text("Input is hidden."),
        ),
        rx.checkbox("Show input", checked=State.show, on_change=State.set_show),
    )


# Create app instance and add index page.
app = rx.App()
app.add_page(index)

The important bit is

        if isinstance(on_click, rx.EventChain):
            on_click = rx.utils.format.format_prop(on_click)

I updated the ResizeWatcher code in the previous discussion, but I think this is a framework bug that needs to be addressed for consistency.

[Edited: using rx.utils.format_prop now instead of format_event_chain]

@kumaraguru1735
Copy link
Contributor Author

please update here, if you updated new codes for Resize Watcher
Thank you

@masenf
Copy link
Collaborator

masenf commented Feb 16, 2024

@kumaraguru1735 As mentioned, i updated the ResizeWatcher code in the original discussion: https://github.com/orgs/reflex-dev/discussions/2462#discussioncomment-8252786

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants