Лучше всего использовать флаг loading
, который устанавливается на true
непосредственно перед началом запроса, а затем на false
, когда запрос возвращается.Затем вы можете использовать этот флаг для условного рендеринга вашего индикатора выполнения!
getPlayerValues() {
this.setState({ loading: true });
fetch("https://jsonplaceholder.typicode.com/comments")
.then(response => response.json())
.then(comments => {
this.setState({
loading: false,
comments: comments
});
});
}
render() {
const { comments, loading } = this.state
// active comments can be derived so no need to store them in state :)
const activeComments = comments.slice(0, 10);
// render your progress bar
if(loading) return <LinearDeterminate />;
// render everything else once loading === false
return (
<div>
{activeComments.map(comment => (
<RecipeReviewCard
key={comment.id}
comment={comment} {/* already passing comment prop here */}
commentId={comment.id} {/* so there's need to pass the these props */}
cardContent={comment.name} {/* just access via this.props.comment */}
cardBelowContent={comment.body}
/>
))}
</div>
)
}