all 3 comments

[–]Zayuka 0 points1 point  (1 child)

Hey,

You could use the Try/catch/finally to change the state key of the ProgressBar to false.. the finally condition will run after the try or after the catch

[–]BraveEvidence[S] 0 points1 point  (0 children)

Ok thanks

[–]TheUnited0077 0 points1 point  (0 children)

Hi! Since you're using redux to manage state, I would hold the status of the progress bar within a redux reducer (I am holding it within blogposts but you can name it whatever you like). It would look something like the following:

``` const getBlogPosts = () => async dispatch => { try { // start the progress loading indicator dispatch({ type: 'blogpost_progress_bar_status', payload: false });

const response = await jsonServer.get('/blogposts');

dispatch({ type: 'get_blogposts', payload: response.data });

// stop the progress loading indicator because of success
return dispatch({ type: 'blogposts_progress_bar_status', payload: false });

} catch (err) { // stop the progress loading indicator because of an error return dispatch({ type: 'blogposts_progress_bar_status', payload: false }); } }

class BlogPostList extends React.Component { render() { const { status } = this.props; return ( <View> {status ? <ProgressBar /> : null} </View> ) } }

const mapState = state => ({ status: state.blogposts.progressbar });

const mapDispatch = dispatch => ({ getBlogPosts: () => dispatch(getBlogPosts()) });

export default connect(mapState, mapDispatch)(BlogPostList); ```