I'm using Rails
with webpacker
with react
.
I'm loading my components like this in my view file:
<div id="mycomponent"></div>
<%= javascript_pack_tag 'components/mycomponent' %>
In mycomponent
, I have:
document.addEventListener('DOMContentLoaded', () => {
ReactDOM.render(
<MyComponent />,
document.getElementById('mycomponent'),
)
})
So on initial page load, mycomponent
is mounted.
But when I visit another page, hit back or click on a link to the dashboard (in this case), the component doesn't load. Had to hit refresh to load it.
I think it has something to do with some caching techinques that Rails
is using?
How do I get the components to load on every request