repeat-scope.tsx 616 B

1234567891011121314151617181920212223
  1. import { createContext, useContext, type ParentProps } from "solid-js";
  2. export interface RepeatScopeValue {
  3. item: unknown;
  4. index: number;
  5. basePath: string;
  6. }
  7. const RepeatScopeContext = createContext<RepeatScopeValue | null>(null);
  8. export function RepeatScopeProvider(props: ParentProps<RepeatScopeValue>) {
  9. return (
  10. <RepeatScopeContext.Provider
  11. value={{ item: props.item, index: props.index, basePath: props.basePath }}
  12. >
  13. {props.children}
  14. </RepeatScopeContext.Provider>
  15. );
  16. }
  17. export function useRepeatScope(): RepeatScopeValue | null {
  18. return useContext(RepeatScopeContext);
  19. }