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

Add auto scroll #4790

Merged
merged 4 commits into from
Feb 18, 2025
Merged

Add auto scroll #4790

merged 4 commits into from
Feb 18, 2025

Conversation

adhami3310
Copy link
Member

import reflex as rx


class State(rx.State):
    messages: rx.Field[list[str]] = rx.field([])

    @rx.event
    def add_message(self):
        self.messages.append(f"Message {len(self.messages) + 1}")


def index():
    return rx.vstack(
        rx.auto_scroll(
            rx.foreach(State.messages, lambda message: rx.text(message)),
            height="300px",
            width="300px",
            border="1px solid red",
        ),
        rx.button("Add Message", on_click=State.add_message),
        padding="200px",
    )


app = rx.App()
app.add_page(index)

Copy link

codspeed-hq bot commented Feb 10, 2025

CodSpeed Performance Report

Merging #4790 will not alter performance

Comparing add-auto_scroll (de183bf) with main (dd5b817)

Summary

✅ 12 untouched benchmarks

@adhami3310
Copy link
Member Author

we should have this for 0.7.1, it makes making a chat app interface much easier

Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it work inside an rx.cond where it wont end up getting memoized?

@adhami3310
Copy link
Member Author

does it work inside an rx.cond where it wont end up getting memoized?

it generally works, even without the memoization thing, but that helps specifically to reduce calls to useEffect (which you might have noticed, would run on every re-render)

@tgberkeley tgberkeley merged commit 3129dda into main Feb 18, 2025
43 checks passed
@tgberkeley tgberkeley deleted the add-auto_scroll branch February 18, 2025 19:52
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

Successfully merging this pull request may close these issues.

3 participants