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

Doesn't load any component if navigated through react-router #4

Open
mahesh1996 opened this issue Jun 28, 2017 · 0 comments
Open

Doesn't load any component if navigated through react-router #4

mahesh1996 opened this issue Jun 28, 2017 · 0 comments

Comments

@mahesh1996
Copy link

Consider below example.
We have 3 pages(e.g home, blogs, contact). When first time any page(e.g home) is loaded by any way(through react-router or through direct URL hit), then Facebook SDK is loaded and facebook-plugins component(e.g FBCommentsCount) on that pages is displayed. But after that if we navigate through react-router to any page(e.g blogs), then any facebook-plugins component(e.g FBComments) on that page(e.g blogs) is not being rerendered even though componentDidUpdate() method of that component(e.g FBComments) is called.

To overcome this problem, I have to implement componentWillUnMount() method in the facebook-plugins component which I was using(e.g FBComments, FBCommentsCount).
I added following code and it is working now.

componentWillUnmount = () => {
        if (document.getElementById('facebook-jssdk')) {
            let fbSdk = document.getElementById('facebook-jssdk');
            fbSdk.parentNode.removeChild(fbSdk);
        }
        if (window.FB) {
            delete window.FB;
        }
        if (document.getElementById('fb-root')) {
            let fbRoot = document.getElementById('fb-root');
            fbRoot.parentNode.removeChild(fbRoot);
        }
    }

I have to unload sdk every time component is un mounted and load it again as if it was loaded first time to let component render.
Why it is not woring in normal cases even componentDidUpdate() is being called?
What could be the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant