✨ Announcing our seed funding led by Lux Capital! Read more about it on our blog
DocsBlogChangelog

Search documentation...

/

Star

12k+

[ Learn ]

[ Concepts ]

[ Reference ]

Memoization


By default, Reflex will re-render the entire page every time the state changes. This is fine for small apps, but can be slow for larger apps.
You can prevent unnecessary rendering by memoizing components, which can greatly improve your app's performance. Just add the @rx.memo decorator to a component function to make it memoized, and list its props as arguments.
The memoized component can be used like any other component. Use keyword arguments to pass in the component's props.

This Heading Won't Rerender

@rx.memo
def fixed_header(text: str) -> rx.Component:
    """A fixed header that doesn't change when the state changes."""
    return rx.heading(text)


def index():
    return fixed_header(text="This Heading Won't Rerender")
← Custom VarsWrapping React →

Copyright © 2023 Pynecone, Inc.