Latest repo

This commit is contained in:
Marc
2025-06-02 16:42:16 +00:00
parent 53ddf1a329
commit cde5fae175
27907 changed files with 3875388 additions and 1 deletions

View File

@@ -0,0 +1 @@
export default function useCachedValue<T>(getter: () => T): () => T;

View File

@@ -0,0 +1,15 @@
'use client';
import { useRef } from 'react';
import { isDefined } from '../utils.js';
export default function useCachedValue(getter) {
const ref = useRef(undefined);
const currentValue = ref.current;
if (isDefined(currentValue)) {
return () => currentValue;
}
return () => {
const value = getter();
ref.current = value;
return value;
};
}

View File

@@ -0,0 +1,2 @@
import type { DocumentContextType } from '../types.js';
export default function useDocumentContext(): DocumentContextType;

View File

@@ -0,0 +1,5 @@
import { useContext } from 'react';
import DocumentContext from '../../DocumentContext.js';
export default function useDocumentContext() {
return useContext(DocumentContext);
}

View File

@@ -0,0 +1,2 @@
import type { OutlineContextType } from '../types.js';
export default function useOutlineContext(): OutlineContextType;

View File

@@ -0,0 +1,5 @@
import { useContext } from 'react';
import OutlineContext from '../../OutlineContext.js';
export default function useOutlineContext() {
return useContext(OutlineContext);
}

View File

@@ -0,0 +1,2 @@
import type { PageContextType } from '../types.js';
export default function usePageContext(): PageContextType;

View File

@@ -0,0 +1,5 @@
import { useContext } from 'react';
import PageContext from '../../PageContext.js';
export default function usePageContext() {
return useContext(PageContext);
}

View File

@@ -0,0 +1,21 @@
type State<T> = {
value: T;
error: undefined;
} | {
value: false;
error: Error;
} | {
value: undefined;
error: undefined;
};
type Action<T> = {
type: 'RESOLVE';
value: T;
} | {
type: 'REJECT';
error: Error;
} | {
type: 'RESET';
};
export default function useResolver<T>(): [State<T>, React.Dispatch<Action<T>>];
export {};

View File

@@ -0,0 +1,16 @@
import { useReducer } from 'react';
function reducer(state, action) {
switch (action.type) {
case 'RESOLVE':
return { value: action.value, error: undefined };
case 'REJECT':
return { value: false, error: action.error };
case 'RESET':
return { value: undefined, error: undefined };
default:
return state;
}
}
export default function useResolver() {
return useReducer((reducer), { value: undefined, error: undefined });
}