blueberryapps / react-load-script

React component that makes it easy to load 3rd party scripts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't change the component once it's mounted to the DOM

0xjohnnycagewins opened this issue · comments

I have a use case where the src element of the script tag changes according to the locale used on the website. Since the script src is passed using the url prop, I thought the component would re-render when changing it, but it doesn't. After looking at your code I realized that that the component is never rendered using render(). Rather, you're using observers created in componentDidMount(). It means that once the component has been mounted to the DOM, it will never be re-rendered again.

I know that because of this design choice it probably won't be that easy to make it possible for the component render using the render() method so it gets re-rendered when props change without a possible (major) refactoring. Just wanted to let you guys know about it if you never encountered the problem. If you don't plan on implementing this, maybe adding a note to the documentation would help some people save time since I had to check your code to understand why my component was not rendering correctly.

#14 might be related to this - I haven't used react-router enough so far to fully understand the problem.

Just saw this is a duplicate of #1. Closing.