Search code examples
angularngrxngrx-storeangular-ngrx-datangrx-data

How to update Store with NgRX Data?


My component structure

enter image description here

In case.component im caching the case data in Case entity of store then i fetch that from child components (case-actions, case-activity... etc).

But when i update remotely the Case from any child component I dont know how to refresh the cached data in parent component (case.component) to replicate that on child components again.

Im trying to do with best practices.


Solution

  • Best practice:

    • You shouldnt fetch the data from a child component, the parent should fetch the data then pass it to the children using an @Input() and you should update your store from the parent aswell by using an @Output() that is triggered by the children. That way, the parent(container) have almost all the logic.

    Quick fix that I don't recommend:

    • If you just want a fix, subscribe to your selector in the children and emit the value to the parent using an @Output()