-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor cache and provider to support SSR
- add name prop to provider - update tsconfig target to ES2020
- Loading branch information
1 parent
63d5cb7
commit 1d331b1
Showing
6 changed files
with
42 additions
and
27 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export declare global { | ||
interface Window { | ||
REACT_INLINESVG_CACHE_NAME?: string; | ||
REACT_INLINESVG_PERSISTENT_CACHE?: boolean; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,17 @@ | ||
import { ReactNode, useEffect } from 'react'; | ||
import { ReactNode } from 'react'; | ||
|
||
import { canUseDOM } from './helpers'; | ||
|
||
interface Props { | ||
children: ReactNode; | ||
name?: string; | ||
} | ||
|
||
declare global { | ||
interface Window { | ||
REACT_INLINESVG_PERSISTENT_CACHE?: boolean; | ||
} | ||
} | ||
|
||
export default function CacheProvider({ children }: Props) { | ||
window.REACT_INLINESVG_PERSISTENT_CACHE = true; | ||
|
||
useEffect(() => { | ||
export default function CacheProvider({ children, name }: Props) { | ||
if (canUseDOM()) { | ||
window.REACT_INLINESVG_CACHE_NAME = name; | ||
window.REACT_INLINESVG_PERSISTENT_CACHE = true; | ||
|
||
return () => { | ||
delete window.REACT_INLINESVG_PERSISTENT_CACHE; | ||
}; | ||
}, []); | ||
} | ||
|
||
return children; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ | |
"noUnusedLocals": false, | ||
"module": "esnext" | ||
}, | ||
"include": ["**/*"] | ||
"include": ["**/*", "../src/**/*"] | ||
} |
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