Last active
February 13, 2017 13:00
-
-
Save tetsuyainfra/355e8a06e6e4a8a50e8fbf4bcff38e1f to your computer and use it in GitHub Desktop.
turbolinks + react bootstrapはたぶんこんなかんじ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ページ読み込みが完了した時に実行 | |
document.addEventListener("DOMContentLoaded", e => { | |
console.log('fired ->', e.type, e.timeStamp) | |
// turbolinksを有効にしている時 | |
document.addEventListener('turbolinks:load', (evt)=>{ | |
console.log('will render ->', evt.type, evt.timeStamp) | |
let elm = document.getElementById('padapp') | |
if (!elm) { return ; } | |
ReactDOM.render(<Hello name="React" />, elm) | |
// cacheとリクエスト結果の2回呼び出されることになるので、 | |
// 一回だけイベントを実行するようにオプションで設定する | |
// 対応ブラウザがどうなってるか分からないので、onceオプション以外の実装も調べてみる? | |
document.addEventListener('turbolinks:before-render', (evt)=>{ | |
console.log('will unmountComponentAtNode ->', evt.type, evt.timeStamp) | |
ReactDOM.unmountComponentAtNode(elm) | |
}, {once: true}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment