ui-next: refactor code structure

This commit is contained in:
Baoshuo committed 2026-05-10 01:12:46 +08:00
1 parent e147b176fb
commit 0b72aea9ab
6 files changed
+8 -8

No files matched your search

+2 -2
View File
@@ -1,4 +1,4 @@
export type { Context } from './src/context';
export { usePageData } from './src/pageData';
export type { PageData } from './src/pageData';
export { usePageData } from './src/context/pageData';
export type { PageData } from './src/context/pageData';
export type { ComponentName } from './src/registry';
+2 -2
View File
@@ -1,8 +1,8 @@
import { usePageData } from './pageData';
import { usePageData } from './context/pageData';
import { Component } from './registry';
const AppInner = Component('page:app', () => {
const { data } = usePageData();
const data = usePageData();
return <div>app, page:{data.name}</div>;
});
@@ -1,6 +1,6 @@
import {
after, before, Component, patch,
} from './registry';
} from '../registry';
export interface Context {
before: typeof before;
@@ -24,8 +24,8 @@ export function PageDataProvider({ initial, children }: { initial: PageData, chi
}
// eslint-disable-next-line react-refresh/only-export-components
export function usePageData(): PageDataContextValue {
export function usePageData(): PageData {
const ctx = useContext(PageDataContext);
if (!ctx) throw new Error('usePageData must be used within PageDataProvider');
return ctx;
return ctx.data;
}
+1 -1
View File
@@ -3,7 +3,7 @@ import { createRoot } from 'react-dom/client';
import plugins from 'virtual:hydro-plugins';
import App from './App';
import { createContext } from './context';
import { type PageData, PageDataProvider } from './pageData';
import { type PageData, PageDataProvider } from './context/pageData';
const ctx = createContext();
for (const plugin of plugins) {
File renamed without changes.