Hi guys,
I’m trying to get my state in my component. class, where I need to dispatch an action and update the state after an HTTP service wrapper receives a successful response. I’m following the docs state
binding command and state change from here, where I can see my state in the view, but I can’t import / inject the global state in my sidebar component.
I would highly appreciate it if someone could help with a tip here. I’m using Aurelia 2.
I found keywords & state
, which works for the view, but what If I want to do the following:
async attached() {
await httpService.getCases()......
store.dispatch({type: "updateCases", value: response})
}
how can I get the updated state after the dispatch?
Hi Vladyn,
Correct me if I am misunderstanding. But, I believe you’re after the fromState
decorator which is detailed in the docs here.
export class AutoSuggest {
@fromState(state => state.cases)
keywords: string;
}
Let me know how you go.
2 Likes
Hi @dwaynecharrington,
Thanks for the tip. I actually tried this, but I had a small misstyping. This one works perfectly. I had to fix my eslint configuration regarding this post: Eslint Error: Parsing error: Unexpected character '@' · Issue #13502 · eslint/eslint · GitHub.