0

I want to populate NGRX store with initial dummy data when ng serve, so my devs who are working on the app don't have to comment/uncomment out mock data manually while they are developing.

I have a JSON file with mock data, I just want to know what the best practice is to populate the store during ng serve.

  • 3
    In ngOnInit() in the app.component, ```if (!environment.production) { ... load your json }``` , this should do the trick. – CevaComic Nov 16 '22 at 23:53

1 Answers1

0
  1. Create a Reducer event (on(...)) that get the containt of json file and set it in the state.
  2. Link the Reducer event to an Action.
  3. Dispatch the Reducer in the app.component.ts ngOnInit after a suitable condition (like to check the environment or so).

Note: if the json file is too big so try to show a message to notify the user to wait.

Jamil
  • 181
  • 5
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 22 '22 at 05:02