mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
ui-next: refactor code structure
This commit is contained in:
6 files changed
+8
-8
No files matched your search
@@ -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';
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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.
Reference in new issue
Block a user