Skip to content

Instantly share code, notes, and snippets.

@deptno deptno/block1.typescript Secret
Created Feb 9, 2020

Embed
What would you like to do?
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
You can’t perform that action at this time.