Skip to content

FastAPI routes and fetch requests #660

Answered by rmorshea
tclasen asked this question in Question
Discussion options

You must be logged in to vote

All the code you write with IDOM is server-side. You have access to all the same data that your normal FastAPI routes would so there's no need to request data from a route. You might write this in the following way:

from idom import component, use_effect, use_state

@component
def MyTable():
    table_rows, set_table_rows = use_state([])

    @use_effect
    def get_table_rows_from_database():
        rows_from_database = get_rows_from_database(...)
        set_table_rows(rows_from_database)

    if not table_rows:
        return LoadingTableSpinner()
    else:
        return html.table(...)  # make a table out of `table_rows`

If your get_rows_from_database function happens to be async th…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@rmorshea
Comment options

@tclasen
Comment options

@tclasen
Comment options

@rmorshea
Comment options

Answer selected by tclasen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants