I am hoping that someone can point me to the best way to handle loading state in a top level Reactrb component with is lazy loading data through Reactive Record.
My gaol is for the top level component to display a wait state while its children components get the data they need to render and then render the whole component quickly. I don't want individual wait states with child components as this creates a 'jerky' experience when there is a lot of data to load.
If you consider this example:
class PostsWithCommentsList < React::Component::Base
before_mount do
state.posts! Post.all
end
def everything_loaded?
#how do I know when all posts and all comments are loaded?
end
def render
div do
ul do
state.posts.each do |post|
li { post.title }
ul do
post.comments.each do |comment|
li { comment.body }
end
end
end
end if everything_loaded?
end
end
end
How do I get the everything_loaded? method to check that all th Posts and all the Comments have been loaded so the component draws quickly and smoothly?
All help very welcome. Thank you