Spaces:
Paused
Paused
Download novel-reader/src/dataSync.jsx from tanlang002/tupload07: direct link, hf CLI and curl.
- Browser
- Download file 623 Bytes
-
https://huggingface.co/spaces/tanlang002/tupload07/resolve/main/novel-reader/src/dataSync.jsx
- Command line
-
hf download hf://spaces/tanlang002/tupload07/novel-reader/src/dataSync.jsx
-
curl -L -o dataSync.jsx https://huggingface.co/spaces/tanlang002/tupload07/resolve/main/novel-reader/src/dataSync.jsx
623 Bytes
| /* 全局数据同步:书架 / 进度 / 缓存发生变化时通知其他页面刷新。 */ | |
| import { createContext, useContext, useMemo, useState } from 'react'; | |
| const DataSyncContext = createContext({ version: 0, notify: () => {} }); | |
| export function DataSyncProvider({ children }) { | |
| const [version, setVersion] = useState(0); | |
| const value = useMemo( | |
| () => ({ | |
| version, | |
| notify: () => setVersion((v) => v + 1), | |
| }), | |
| [version], | |
| ); | |
| return <DataSyncContext.Provider value={value}>{children}</DataSyncContext.Provider>; | |
| } | |
| export function useDataSync() { | |
| return useContext(DataSyncContext); | |
| } | |