Issue
I have a class Store which incapsulates State (mobx used).
export class Store<State> {
@observable
public state: State;
constructor(protected rootStore: RootStore, state: State) {
this.state = state || ({} as State);
}
@action
setState(state: State) {
this.state = {
...this.state,
...state
};
}
}
And I'm trying to implement a class UserState
:
interface UserState {
authorised?: boolean;
loading?: boolean;
name?: string;
balance?: number;
}
export class UserStore extends Store<UserState> {
constructor(rootStore: RootStore) {
super(rootStore, {
authorised: false,
loading: true,
name: ''
})
}
}
Everything seems right for me, but I have an error:
ReferenceError: Cannot access 'Store' before initialization
I simply trying to set some default values in a store and it seems in a Store
it's inside a constructor, so it's initialized obviously.
Solution
Problem was solved by moving Store
class to isolated file, before it was in the same file as the global store.
Answered By - zishe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.