Skip to content

how to implement a progress bar that renders multiple times when a function is running? #1194

Answered by Archmonger
qguo-MCC asked this question in Question

You must be logged in to vote

There are two common approaches you can take to update a status bar

  1. Store the value in a something like redis or mysql and have your component poll for it via use_effect
@component
def progress_bar_app():
    percentage, set_percentage = hooks.use_state(0)
    
    @hooks.use_effect
    async def update_percentage():
        while True:
            await sleep(1)
            # Retrieve the current percentage from something like a database or redis.
            current = await get_percentage()
            set_percentage(current)

    return ...
  1. Have the percentage be a component prop (get the actual value from a parent component).

This is useful if you have a parent component that is a…

Replies: 1 comment

You must be logged in to vote
0 replies
Answer selected by Archmonger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants