z4cd4g
Last Updated: September 15, 2018
·
759
· naohiro

Integrate with Turbolinks and webpacker react

Without turbolinks, your pack will look like following

document.addEventListener('DOMContentLoaded', () => {
  ReactDOM.render(
    <Component />,
    document.getElementById('react-component'),
  )
})

However, this won't work well with turbolinks. You need to update event listener like following

document.addEventListener('turbolinks:load', function() {
  ReactDOM.render(
    <Component />,
    document.getElementById('react-component'),
  )
})

Reference: https://github.com/rails/webpacker/issues/161