CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-remix-run--react

React DOM bindings for Remix web framework providing components, hooks, and utilities for full-stack React applications

Pending
Overview
Eval results
Files

react-router-integration.mddocs/

React Router Integration

Complete re-export of React Router components, hooks, and utilities for routing functionality, seamlessly integrated with Remix's data loading and server-side rendering capabilities.

Capabilities

Navigation Components

Core React Router components for declarative navigation and route rendering.

/**
 * Declarative navigation component that triggers navigation when rendered
 * @param props - Navigation configuration
 * @returns React element that triggers navigation
 */
function Navigate(props: NavigateProps): ReactElement;

/**
 * Renders the child route component for the current location
 * @param props - Optional outlet configuration
 * @returns React element containing the matched child route
 */
function Outlet(props?: OutletProps): ReactElement;

/**
 * Container component for route definitions
 * @param props - Routes configuration
 * @returns React element containing route matching logic
 */
function Routes(props: RoutesProps): ReactElement;

/**
 * Defines a single route in the application
 * @param props - Route configuration
 * @returns Route definition (not directly rendered)
 */
function Route(props: RouteProps): ReactElement;

interface NavigateProps {
  /** Path to navigate to */
  to: string | Partial<Path>;
  /** Whether to replace the current history entry */
  replace?: boolean;
  /** State to pass with the navigation */
  state?: any;
  /** Relative path resolution */
  relative?: "route" | "path";
}

interface OutletProps {
  /** Context data to pass to child routes */
  context?: unknown;
}

interface RouteProps {
  /** Path pattern to match */
  path?: string;
  /** Route element to render */
  element?: ReactElement;
  /** Index route indicator */
  index?: boolean;
  /** Child routes */
  children?: ReactNode;
  /** Whether path matching is case sensitive */
  caseSensitive?: boolean;
  /** Route ID for data loading */
  id?: string;
  /** Loader function for data loading */
  loader?: LoaderFunction;
  /** Action function for form handling */
  action?: ActionFunction;
  /** Error boundary element */
  errorElement?: ReactElement;
  /** Route handle for custom metadata */
  handle?: RouteHandle;
  /** Should revalidate function */
  shouldRevalidate?: ShouldRevalidateFunction;
}

Usage Examples:

import { Routes, Route, Navigate, Outlet } from "@remix-run/react";

// Basic route definitions
function AppRoutes() {
  return (
    <Routes>
      <Route path="/" element={<Home />} />
      <Route path="/about" element={<About />} />
      <Route path="/users" element={<UsersLayout />}>
        <Route index element={<UsersList />} />
        <Route path=":userId" element={<UserDetail />} />
      </Route>
      <Route path="/old-path" element={<Navigate to="/new-path" replace />} />
    </Routes>
  );
}

// Layout with outlet
function UsersLayout() {
  return (
    <div>
      <h1>Users</h1>
      <nav>{/* user navigation */}</nav>
      <main>
        <Outlet />
      </main>
    </div>
  );
}

Navigation Hooks

Hooks for programmatic navigation and location access.

/**
 * Returns a function for programmatic navigation
 * @returns Function to navigate to different routes
 */
function useNavigate(): NavigateFunction;

/**
 * Returns the current location object
 * @returns Current location with pathname, search, hash, state, and key
 */
function useLocation(): Location;

/**
 * Returns the current navigation state
 * @returns Information about ongoing navigation
 */
function useNavigation(): Navigation;

/**
 * Returns the type of the current navigation
 * @returns Navigation type (PUSH, REPLACE, or POP)
 */
function useNavigationType(): NavigationType;

type NavigateFunction = (
  to: string | number | Partial<Path>,
  options?: NavigateOptions
) => void;

interface NavigateOptions {
  replace?: boolean;
  state?: any;
  preventScrollReset?: boolean;
  relative?: "route" | "path";
}

interface Location {
  /** Current pathname */
  pathname: string;
  /** Current search string */
  search: string;
  /** Current hash fragment */
  hash: string;
  /** Navigation state */
  state: unknown;
  /** Unique key for this location */
  key: string;
}

interface Navigation {
  /** Current navigation state */
  state: "idle" | "loading" | "submitting";
  /** Target location for navigation */
  location?: Location;
  /** Form data being submitted */
  formData?: FormData;
  /** JSON data being submitted */
  json?: any;
  /** Text data being submitted */
  text?: string;
  /** Form method */
  formMethod?: string;
  /** Form action */
  formAction?: string;
}

type NavigationType = "POP" | "PUSH" | "REPLACE";

Usage Examples:

import { useNavigate, useLocation, useNavigation } from "@remix-run/react";

// Programmatic navigation
function LoginButton() {
  const navigate = useNavigate();
  const location = useLocation();
  
  const handleLogin = async () => {
    const success = await login();
    if (success) {
      // Navigate to the page they were trying to access, or home
      const from = location.state?.from?.pathname || "/";
      navigate(from, { replace: true });
    }
  };
  
  return <button onClick={handleLogin}>Login</button>;
}

// Location-based rendering
function LocationDisplay() {
  const location = useLocation();
  
  return (
    <div>
      <p>Current path: {location.pathname}</p>
      <p>Search params: {location.search}</p>
      {location.state && <p>State: {JSON.stringify(location.state)}</p>}
    </div>
  );
}

// Navigation state indicator
function NavigationIndicator() {
  const navigation = useNavigation();
  
  if (navigation.state === "loading") {
    return <div className="loading-bar">Loading...</div>;
  }
  
  if (navigation.state === "submitting") {
    return <div className="loading-bar">Submitting...</div>;
  }
  
  return null;
}

Route Parameters and Search

Hooks for accessing route parameters and URL search parameters.

/**
 * Returns the current route parameters
 * @returns Object containing route parameters
 */
function useParams<K extends string = string>(): Readonly<Params<K>>;

/**
 * Returns the current URL search parameters
 * @returns Tuple of URLSearchParams and setter function
 */
function useSearchParams(): [URLSearchParams, SetURLSearchParams];

/**
 * Returns a resolved path object
 * @param to - Path to resolve
 * @param options - Resolution options
 * @returns Resolved path object
 */
function useResolvedPath(to: string | Partial<Path>, options?: { relative?: "route" | "path" }): Path;

type Params<K extends string = string> = {
  readonly [key in K]: string | undefined;
};

type SetURLSearchParams = (
  nextInit: URLSearchParamsInit | ((prev: URLSearchParams) => URLSearchParamsInit),
  navigateOptions?: NavigateOptions
) => void;

Usage Examples:

import { useParams, useSearchParams } from "@remix-run/react";

// Route parameters
function UserProfile() {
  const { userId } = useParams();
  
  if (!userId) {
    return <div>User not found</div>;
  }
  
  return <div>User ID: {userId}</div>;
}

// Search parameters
function ProductFilter() {
  const [searchParams, setSearchParams] = useSearchParams();
  
  const category = searchParams.get("category") || "all";
  const sortBy = searchParams.get("sort") || "name";
  
  const updateFilter = (key: string, value: string) => {
    setSearchParams(prev => {
      const newParams = new URLSearchParams(prev);
      newParams.set(key, value);
      return newParams;
    });
  };
  
  return (
    <div>
      <select 
        value={category} 
        onChange={(e) => updateFilter("category", e.target.value)}
      >
        <option value="all">All Categories</option>
        <option value="electronics">Electronics</option>
        <option value="clothing">Clothing</option>
      </select>
      
      <select 
        value={sortBy} 
        onChange={(e) => updateFilter("sort", e.target.value)}
      >
        <option value="name">Name</option>
        <option value="price">Price</option>
        <option value="date">Date</option>
      </select>
    </div>
  );
}

Additional Routing Utilities

Additional hooks and utilities for advanced routing scenarios.

/**
 * Returns the current route match
 * @param pattern - Pattern to match against
 * @returns Match object or null
 */
function useMatch<T extends string>(pattern: PathPattern<T> | string): PathMatch<T> | null;

/**
 * Returns an href string for the given path
 * @param to - Path to generate href for
 * @param options - Resolution options
 * @returns href string
 */
function useHref(to: string | Partial<Path>, options?: { relative?: "route" | "path" }): string;

/**
 * Returns whether the component is rendered within a router context
 * @returns Boolean indicating if in router context
 */
function useInRouterContext(): boolean;

/**
 * Returns outlet context data
 * @returns Context data passed from parent route
 */
function useOutletContext<T = unknown>(): T;

/**
 * Returns the current outlet element
 * @returns The current outlet element
 */
function useOutlet(): ReactElement | null;

/**
 * Returns revalidator for manually triggering data revalidation
 * @returns Revalidator with revalidate function and state
 */
function useRevalidator(): Revalidator;

interface Revalidator {
  /** Function to trigger revalidation */
  revalidate(): void;
  /** Current revalidation state */
  state: "idle" | "loading";
}

/**
 * Registers a callback to be called before the page unloads
 * @param callback - Function to call before unload
 */
function useBeforeUnload(callback: (event: BeforeUnloadEvent) => void): void;

/**
 * Returns the action URL for the current form context
 * @returns The action URL string
 */
function useFormAction(): string;

/**
 * Returns a click handler for programmatic navigation
 * @param to - Navigation target
 * @param options - Navigation options
 * @returns Click handler function
 */
function useLinkClickHandler<E extends Element = HTMLAnchorElement>(
  to: To, 
  options?: { 
    target?: React.HTMLAttributeAnchorTarget; 
    replace?: boolean; 
    state?: any; 
    preventScrollReset?: boolean; 
    relative?: RelativeRoutingType; 
  }
): (event: React.MouseEvent<E, MouseEvent>) => void;

/**
 * Returns a submit function for programmatic form submission
 * @returns Submit function
 */
function useSubmit(): SubmitFunction;

/**
 * Returns a blocker for preventing navigation
 * @param blocker - Blocker function
 * @returns Blocker state
 */
function useBlocker(blocker: BlockerFunction): Blocker;

/**
 * Returns whether a view transition is active for the given navigation
 * @param to - Navigation target
 * @param opts - Options for relative navigation
 * @returns Whether view transition is active
 */
function useViewTransitionState(to: To, opts?: { relative?: RelativeRoutingType }): boolean;

/**
 * Prompts the user before navigation (unstable API)
 * @param message - Prompt message or boolean to enable/disable
 */
function unstable_usePrompt(message: string | boolean): void;

/**
 * Returns the current async error, if any
 * @returns Current async error or undefined
 */
function useAsyncError(): Error | undefined;

/**
 * Returns the resolved async value
 * @returns The resolved async value
 */
function useAsyncValue<T = unknown>(): T;

/**
 * Returns all active fetchers
 * @returns Array of active fetchers
 */
function useFetchers(): Fetcher[];

/**
 * Returns the current route error
 * @returns Current route error
 */
function useRouteError(): unknown;

/**
 * Renders routes from route objects
 * @param routes - Route objects to render
 * @param locationArg - Optional location override
 * @returns Rendered routes
 */
function useRoutes(routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null;

Routing Utilities

Utility functions for route manipulation and path handling.

/**
 * Creates a path string from a location object
 * @param location - Location object
 * @returns Path string
 */
function createPath(location: Partial<Location | Path>): string;

/**
 * Creates routes from React children elements
 * @param children - Route elements
 * @returns Route objects
 */
function createRoutesFromChildren(children: ReactNode): RouteObject[];

/**
 * Creates routes from React elements
 * @param elements - Route elements
 * @returns Route objects
 */
function createRoutesFromElements(elements: ReactNode): RouteObject[];

/**
 * Creates URLSearchParams from init value
 * @param init - Initial search params
 * @returns URLSearchParams instance
 */
function createSearchParams(init?: URLSearchParamsInit): URLSearchParams;

/**
 * Generates a path with parameters filled in
 * @param pattern - Path pattern
 * @param params - Parameters to fill
 * @returns Generated path
 */
function generatePath<Path extends string>(pattern: Path, params?: PathParams<Path>): string;

/**
 * Matches a path against a pattern
 * @param pattern - Pattern to match
 * @param pathname - Path to test
 * @returns Match result or null
 */
function matchPath<ParamKey extends string = string>(
  pattern: PathPattern<ParamKey> | string,
  pathname: string
): PathMatch<ParamKey> | null;

/**
 * Parses a path string into a path object
 * @param path - Path string
 * @returns Path object
 */
function parsePath(path: string): Partial<Path>;

/**
 * Resolves a path relative to the current location
 * @param to - Path to resolve
 * @param fromPathname - Base pathname
 * @returns Resolved path
 */
function resolvePath(to: string | Partial<Path>, fromPathname?: string): Path;

Implementation Notes

  • Full Compatibility: All React Router functionality is preserved and enhanced with Remix features
  • Server-Side Rendering: All components and hooks work correctly during SSR
  • Type Safety: Full TypeScript support with proper type inference
  • Data Integration: Navigation hooks integrate with Remix's data loading system
  • Error Handling: Route-level error boundaries work seamlessly with Remix error handling
  • Performance: Client-side navigation is optimized with prefetching and caching

Install with Tessl CLI

npx tessl i tessl/npm-remix-run--react

docs

application-entry-points.md

data-loading-hooks.md

data-response-utilities.md

document-components.md

forms-and-navigation.md

index.md

react-router-integration.md

type-definitions.md

tile.json