How to use patchState vs setState in NGXS?
问题 I am learning ngxs but I can't understand when should I use patchState and setState ? What's the difference? const state = ctx.getState(); let data = this.service.list(); ctx.setState({ ...state, feedAnimals: data }); vs. let data = this.service.list(); ctx.patchState({ feedAnimals: data }); 回答1: Those two pieces of code are equivalent. patchState is just a short hand version of the setState({...state, ... } code. In future patchState will most likely be evolving to a more useful immutability