Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run action while componentDidMount do not trigger props update #169

Open
dev-johnny-gh opened this issue Aug 9, 2019 · 1 comment
Open
Labels

Comments

@dev-johnny-gh
Copy link

dev-johnny-gh commented Aug 9, 2019

@connect({
  a: 'a',
}, {
  doSomething: () => {
    return {a: 'b'};
  }
})
export class Example extends Component<IProps, IState> {
  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.

@developit
Copy link
Owner

developit commented Oct 17, 2019

Is this in React, or Preact?

It seems like a bug, due to the reversed execution order for componentDidMount(), which causes the child component's method to fire before the parent (wrapper)'s. The issue stems from here:

https://github.com/developit/unistore/blob/master/src/integrations/react.js#L46

One possible solution would be to use a different heuristic for differentiating between SSR and client-side rendering.

@developit developit added the bug label Oct 17, 2019
tumerorkun pushed a commit to tumerorkun/unistore that referenced this issue Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants