The reason for separating hospitals and originals in useContext is to preserve the original data while allowing for filtering or modification operations.
originals: This holds the original hospital data. it is meant to stay unchanged, keeping the hospital list in its initially fetched state. This is useful for resetting to the original state or clearing filters.
hospitals: This is the list of hospitals currently displayed on the screen. it is dynamic data that changes based on filtering, searching, or other operations.
Why separate the Original and Current State? When you add features like filters or searches, you change the data inside the hospitals box. For example, if you say, "Show me only the hospitals in Belleve!" then the hospitals box will contain only the Belleve hospitals. But the original data(originals) stays the same. So, if you wanna "remove the filter and go back to the original list", you can take the data from originals and put it back into hospitals.
The reason for separating
hospitals
andoriginals
inuseContext
is to preserve the original data while allowing for filtering or modification operations.originals
: This holds the original hospital data. it is meant to stay unchanged, keeping the hospital list in its initially fetched state. This is useful for resetting to the original state or clearing filters.hospitals
: This is the list of hospitals currently displayed on the screen. it is dynamic data that changes based on filtering, searching, or other operations.Why separate the Original and Current State? When you add features like filters or searches, you change the data inside the
hospitals
box. For example, if you say, "Show me only the hospitals in Belleve!" then thehospitals
box will contain only the Belleve hospitals. But the original data(originals
) stays the same. So, if you wanna "remove the filter and go back to the original list", you can take the data fromoriginals
and put it back intohospitals
.