Skip to content

Commit f12cef3

Browse files
committed
fix(react-container): should initialize before other component
We have used componentDidMount instead of componentWillMount in #321 But, Almin React Container should be initialized before other component. Because, this component subscribe `Context#onChange`. In other words, Almin React Container can not handle `Context#onchange` when some store has been changed in Other Component#componentDidMount.
1 parent 71217f8 commit f12cef3

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

packages/almin-react-container/src/almin-react-container.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ export class AlminReactContainer {
3535
state: P;
3636
unSubscribe: () => void | null;
3737

38+
onChangeHandler = () => {
39+
this.setState(context.getState());
40+
};
41+
3842
constructor(props: any) {
3943
super(props);
4044
this.state = context.getState();
45+
this.unSubscribe = context.onChange(this.onChangeHandler);
4146
}
4247

4348
shouldComponentUpdate(_nextProps: any, nextState: any) {
@@ -46,13 +51,6 @@ export class AlminReactContainer {
4651
return !shallowEqual(this.state, nextState);
4752
}
4853

49-
componentDidMount() {
50-
const onChangeHandler = () => {
51-
this.setState(context.getState());
52-
};
53-
this.unSubscribe = context.onChange(onChangeHandler);
54-
}
55-
5654
componentWillUnmount() {
5755
if (typeof this.unSubscribe === "function") {
5856
this.unSubscribe();

0 commit comments

Comments
 (0)