developit / developit/unistore

run action while componentDidMount do not trigger props update

Open
#169 1 comment 2 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
2.8k
Forks
134
PR merge metrics
No merged PRs in 30d

Description

```
@connect({
a: 'a',
}, {
doSomething: () => {
return {a: 'b'};
}
})
export class Example extends Component {
componentDidMount() {
this.props.doSomething();
}

componentWillReceiveProps(nextProps) {
console.log("nextProps", nextProps);
}
}
```

this example shows what i had done.

**i triggered an action in componentDidMount, but componentWillReceiveProps can not receive any update.**

i look into the code and found out the problem is the wrapper outside my component register a listener while componentDidMount, but its child componet, **my component, mounted before the wrapper.**

**so when my component run componentDidMount, the wrapper haven't run the subscription method yet. therefore it can't reveive any update.**

so why not use the **componentWillMount** to replace the **componentDidMount**. **componentWillMount** will be triggered in a right order from parent to child. so subscription function can capture and update any changes from the child component.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.