List Ratings
Let's learn how to perform state management in components while loading.
We'll cover the following...
We’ll build a ratings index component that will be responsible for orchestrating the state of all of the product ratings in our survey. This component will iterate over the products and determine whether to render the rating details if a rating by the user exists or the rating form if it doesn’t. The responsibility for rendering rating details will be handled by a stateless “rating show” component and the responsibility for rendering and managing a rating form will be handled by a stateful “rating form” component.
Meanwhile, SurveyLive
will continue to be responsible for managing the overall state and appearance of the survey page. Only if the demographic record exists for the user will the SurveyLive
LiveView render the ratings index component.
In this way, we keep our code organized and easy to maintain because it is adherent to the single responsibility principle—each component has one job to do. By layering these components within the parent SurveyLive
LiveView, we are able to compose a series of small, manageable pieces into one interactive user survey page.
We’ll ...