MayHyeyeonKim / games-for-love-backup

0 stars 0 forks source link

The reason for separating `hospitals` and `originals` in useContext. #3

Open MayHyeyeonKim opened 4 weeks ago

MayHyeyeonKim commented 4 weeks ago

The reason for separating hospitals and originals in useContext is to preserve the original data while allowing for filtering or modification operations.

  1. 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.
  2. 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.

MayHyeyeonKim commented 2 weeks ago

originals는 초기 데이터이자 전체 데이터이므로, 사용자가 필터나 검색을 수행할 때마다 원본 데이터를 기반으로 새로운 결과를 빠르게 계산할 수 있다