-
-
Save deptno/ff1d359a3e24103b1df2529fce9226c4 to your computer and use it in GitHub Desktop.
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
jsx | |
// _app.tsx | |
export default class extends App { | |
handleStorageEvent = (e) => { | |
if (e.key === 'sharedData') { | |
const {sessionId, type, payload} = JSON.parse(e.newValue) | |
// 자신이 보낸 것이 아닐 경우에만 동작을 원할 경우 | |
if (sessionId !== sessioStorage.get('sessionId')) { | |
// 디스패치할 액션을 찾는다. | |
const action = sharedActions[actionType] | |
// 모든 탭에서 실행되는 액션 | |
this.store.dispatch({type, payload}) | |
} | |
} | |
} | |
componentDidMount() { | |
// sessionId 설정 | |
sessionStorage.setItem('sessionId', uuid()) | |
// storage 이벤트 핸들러 등록 | |
addEventListner('storage', this.handleStorageEvent) | |
} | |
componentWillUnMouse() { | |
removeEventListner('storage', this.handleStorageEvent) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment