人生轨迹代码初始化
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Store } from '../utils/store';
|
||||
|
||||
export function useStoreData() {
|
||||
const [data, setData] = useState(Store.get());
|
||||
|
||||
useEffect(() => {
|
||||
const handleUpdate = () => {
|
||||
setData(Store.get());
|
||||
};
|
||||
|
||||
window.addEventListener('store-updated', handleUpdate);
|
||||
return () => window.removeEventListener('store-updated', handleUpdate);
|
||||
}, []);
|
||||
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user