From ddf467c03803ba0d779bae2571102af87ad2df17 Mon Sep 17 00:00:00 2001 From: Jing Hua Date: Sat, 4 Mar 2023 08:59:17 +0800 Subject: [PATCH] implement cache --- src/components/ConfigMenu/ConfigMenu.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/ConfigMenu/ConfigMenu.tsx b/src/components/ConfigMenu/ConfigMenu.tsx index 9bd0d2f..53e19b2 100644 --- a/src/components/ConfigMenu/ConfigMenu.tsx +++ b/src/components/ConfigMenu/ConfigMenu.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import useStore from '@store/store'; import CrossIcon2 from '@icon/CrossIcon2'; @@ -42,6 +42,15 @@ const ConfigMenu = () => { setOpenConfig(false); }; + useEffect(() => { + const storedApiKey = localStorage.getItem('apiKey'); + if (storedApiKey) { + setApiFree(false); + setApiKey(storedApiKey); + _setApiKey(storedApiKey); + } + }, []); + return openConfig ? (
@@ -61,7 +70,7 @@ const ConfigMenu = () => {
setApiFree(true)} @@ -80,7 +89,7 @@ const ConfigMenu = () => {
setApiFree(false)}