mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 17:30:16 +01:00
25 lines
626 B
TypeScript
25 lines
626 B
TypeScript
|
|
import { isJson } from '~/utils/json';
|
||
|
|
|
||
|
|
export default function useMultipleKeys(setUserKey: React.Dispatch<React.SetStateAction<string>>) {
|
||
|
|
function getMultiKey(name: string, userKey: string) {
|
||
|
|
if (isJson(userKey)) {
|
||
|
|
const newKey = JSON.parse(userKey);
|
||
|
|
return newKey[name];
|
||
|
|
} else {
|
||
|
|
return '';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function setMultiKey(name: string, value: number | string | boolean, userKey: string) {
|
||
|
|
let newKey = {};
|
||
|
|
if (isJson(userKey)) {
|
||
|
|
newKey = JSON.parse(userKey);
|
||
|
|
}
|
||
|
|
newKey[name] = value;
|
||
|
|
|
||
|
|
setUserKey(JSON.stringify(newKey));
|
||
|
|
}
|
||
|
|
|
||
|
|
return { getMultiKey, setMultiKey };
|
||
|
|
}
|