refactor: settings to use less useEffects (and therefore less re-renders) (#277)
This commit is contained in:
+18
-15
@@ -44,35 +44,38 @@ export function Provider({
|
|||||||
const [beeDebugApi, setBeeDebugApi] = useState<BeeDebug | null>(null)
|
const [beeDebugApi, setBeeDebugApi] = useState<BeeDebug | null>(null)
|
||||||
const [lockedApiSettings] = useState<boolean>(Boolean(extLockedApiSettings))
|
const [lockedApiSettings] = useState<boolean>(Boolean(extLockedApiSettings))
|
||||||
|
|
||||||
|
const url = beeApiUrl || apiUrl
|
||||||
|
const debugUrl = beeDebugApiUrl || apiDebugUrl
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
try {
|
try {
|
||||||
setBeeApi(new Bee(apiUrl))
|
setBeeApi(new Bee(url))
|
||||||
sessionStorage.setItem('api_host', apiUrl)
|
sessionStorage.setItem('api_host', url)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setBeeApi(null)
|
setBeeApi(null)
|
||||||
}
|
}
|
||||||
}, [apiUrl])
|
}, [url])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (beeApiUrl) setApiUrl(beeApiUrl)
|
|
||||||
}, [beeApiUrl])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (beeDebugApiUrl) setDebugApiUrl(beeDebugApiUrl)
|
|
||||||
}, [beeDebugApiUrl])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
try {
|
try {
|
||||||
setBeeDebugApi(new BeeDebug(apiDebugUrl))
|
setBeeDebugApi(new BeeDebug(debugUrl))
|
||||||
sessionStorage.setItem('debug_api_host', apiDebugUrl)
|
sessionStorage.setItem('debug_api_host', debugUrl)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setBeeDebugApi(null)
|
setBeeDebugApi(null)
|
||||||
}
|
}
|
||||||
}, [apiDebugUrl])
|
}, [debugUrl])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Context.Provider
|
<Context.Provider
|
||||||
value={{ apiUrl, apiDebugUrl, beeApi, beeDebugApi, setApiUrl, setDebugApiUrl, lockedApiSettings }}
|
value={{
|
||||||
|
apiUrl: url,
|
||||||
|
apiDebugUrl: debugUrl,
|
||||||
|
beeApi,
|
||||||
|
beeDebugApi,
|
||||||
|
setApiUrl,
|
||||||
|
setDebugApiUrl,
|
||||||
|
lockedApiSettings,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</Context.Provider>
|
</Context.Provider>
|
||||||
|
|||||||
Reference in New Issue
Block a user