Skip to content

Commit

Permalink
fix: window check
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Apr 15, 2019
1 parent 8a9b88c commit cfbda29
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const Sidebar: SFC = () => {
const addOverlayClass = (isHidden: boolean) => {
const method = !isHidden ? 'add' : 'remove'

if (window && typeof window !== 'undefined' && !isDesktop) {
if (typeof window !== 'undefined' && !isDesktop) {
document.documentElement!.classList[method]('with-overlay')
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ export const Playground: SFC<PlaygroundProps> = ({
}, [])

const addUnloadListener = useCallback(() => {
if (window && typeof window !== 'undefined') {
if (typeof window !== 'undefined') {
window.addEventListener('beforeunload', unloadListener, false)
}
}, [])

const removeUnloadListener = useCallback(() => {
if (window && typeof window !== 'undefined') {
if (typeof window !== 'undefined') {
window.removeEventListener('beforeunload', unloadListener, false)
}
}, [])
Expand All @@ -241,7 +241,7 @@ export const Playground: SFC<PlaygroundProps> = ({
}, [])

useEffect(() => {
if (window && typeof window !== 'undefined') {
if (typeof window !== 'undefined') {
const method = fullscreen ? 'add' : 'remove'
document.body.classList[method]('with-overlay')
}
Expand Down
2 changes: 1 addition & 1 deletion core/docz-theme-default/src/utils/hotkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import hotkeys from 'hotkeys-js'

export const useHotkeys = (key: string, cb: () => any, inputs?: any[]) => {
useEffect(() => {
if (window && typeof window !== 'undefined') {
if (typeof window !== 'undefined') {
hotkeys(key, cb)
return () => hotkeys.unbind(key)
}
Expand Down
6 changes: 3 additions & 3 deletions core/docz-theme-default/src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class Storage {
}

public get(): any {
if (window && typeof window !== 'undefined') {
if (typeof window !== 'undefined') {
try {
const item = window.localStorage.getItem(this.name)
return typeof item === 'string' ? JSON.parse(item) : null
Expand All @@ -16,13 +16,13 @@ export class Storage {
}

public set(value: any): void {
if (window && typeof window !== 'undefined') {
if (typeof window !== 'undefined') {
window.localStorage.setItem(this.name, JSON.stringify(value))
}
}

public delete(): void {
if (window && typeof window !== 'undefined') {
if (typeof window !== 'undefined') {
window.localStorage.removeItem(this.name)
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/docz/src/components/AsyncPlayground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import loadable from '@loadable/component'

const BasePlayground = loadable(() => import('./Playground'))
export const Playground: React.SFC<any> = props =>
window && typeof window !== 'undefined' ? (
typeof window !== 'undefined' ? (
<React.Suspense fallback={null}>
<BasePlayground {...props} />
</React.Suspense>
Expand Down

0 comments on commit cfbda29

Please sign in to comment.