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

Profile route mounted count stays at 1 #31

Closed
mhussa opened this issue Jun 26, 2016 · 2 comments
Closed

Profile route mounted count stays at 1 #31

mhussa opened this issue Jun 26, 2016 · 2 comments
Labels

Comments

@mhussa
Copy link

mhussa commented Jun 26, 2016

I've been tinkering with this and its a nice setup but I don't quite understand how the router and component mount methods work. Whenever I click the 'Me' or 'John' profile links the route mounted stays at 1.

Checked it on the latest versions of firefox and safari. I added some breakpoints and found that the component mount methods are never invoked on clicking the profile links. Couldn't even to get it to stop on the App's handleRoute.

Have I misunderstood how this is meant to work? Any help appreciated, Thanks.

@developit
Copy link
Owner

developit commented Jun 26, 2016

Hi @mhussa - the "me" and "John" routes are handled by the same component. This means switching between the two actually doesn't unmount and remount, rather it's actually just re-rendering the <Profile /> component with new props.

If you add a componentWillReceiveProps() method to the Profile class you will be able to observe the behavior.

You can see an example of a much more fully built-out Profile component in the Nectarine source.

Let me know if that helps ☺

@mhussa
Copy link
Author

mhussa commented Jun 26, 2016

Hello @developit

Thankyou for the quick response! yes it works exactly as you said.

I modified it as follows:

    componentDidMount() {
            // start a timer for the clock:
            this.timer = setInterval(::this.updateTime, 1000);
            this.updateTime();
    }

    componentWillReceiveProps() {
            // every time we get remounted, increment a counter:
            this.setState({ count: this.state.count+1});
    }

Clicking on 'Home' remounts the component and the counter is back at 0, then clicking between profile views increments the count. The comment in the code about remounting threw me a bit.

Thankyou for the clarification.

@mhussa mhussa closed this as completed Jun 26, 2016
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