blob: b6e3b4c7a66397481985720c0b2ce61faa4fe6e7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import { useEffect, useState } from 'react';
import { fetchData } from '~/api/memory';
import { ClashAPIConfig } from '~/types';
export default function useMemory(apiConfig: ClashAPIConfig) {
const memory = fetchData(apiConfig);
const [data, setData] = useState({
inuse: [...memory.inuse],
oslimit: [...memory.oslimit],
labels: [...memory.labels],
});
useEffect(() => {
return memory.subscribe(() => {
setData({
inuse: [...memory.inuse],
oslimit: [...memory.oslimit],
labels: [...memory.labels],
});
});
}, [memory]);
return data;
}
|