Skip to content

Instantly share code, notes, and snippets.

@deptno
Created February 9, 2020 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deptno/ff1d359a3e24103b1df2529fce9226c4 to your computer and use it in GitHub Desktop.
Save deptno/ff1d359a3e24103b1df2529fce9226c4 to your computer and use it in GitHub Desktop.
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