@inertiajs/react 2.3.17 → 3.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.js CHANGED
@@ -1,37 +1,6 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
1
  // src/server.ts
31
- var server_exports = {};
32
- __export(server_exports, {
33
- default: () => import_server.default
34
- });
35
- module.exports = __toCommonJS(server_exports);
36
- var import_server = __toESM(require("@inertiajs/core/server"), 1);
2
+ import { default as default2 } from "@inertiajs/core/server";
3
+ export {
4
+ default2 as default
5
+ };
37
6
  //# sourceMappingURL=server.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/server.ts"],
4
4
  "sourcesContent": ["export { default as default } from '@inertiajs/core/server'\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmC;",
6
- "names": []
5
+ "mappings": ";AAAA,SAAoB,WAAXA,gBAA0B;",
6
+ "names": ["default"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inertiajs/react",
3
- "version": "2.3.17",
3
+ "version": "3.0.0-beta.2",
4
4
  "license": "MIT",
5
5
  "description": "The React adapter for Inertia.js",
6
6
  "contributors": [
@@ -10,7 +10,7 @@
10
10
  "homepage": "https://inertiajs.com/",
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "https://github.com/inertiajs/inertia.git",
13
+ "url": "git+https://github.com/inertiajs/inertia.git",
14
14
  "directory": "packages/react"
15
15
  },
16
16
  "bugs": {
@@ -27,13 +27,11 @@
27
27
  "exports": {
28
28
  ".": {
29
29
  "types": "./types/index.d.ts",
30
- "import": "./dist/index.esm.js",
31
- "require": "./dist/index.js"
30
+ "import": "./dist/index.js"
32
31
  },
33
32
  "./server": {
34
33
  "types": "./types/server.d.ts",
35
- "import": "./dist/server.esm.js",
36
- "require": "./dist/server.js"
34
+ "import": "./dist/server.js"
37
35
  }
38
36
  },
39
37
  "typesVersions": {
@@ -55,14 +53,14 @@
55
53
  "typescript": "^5.9.3"
56
54
  },
57
55
  "peerDependencies": {
58
- "react": "^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
59
- "react-dom": "^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
56
+ "react": "^19.0.0",
57
+ "react-dom": "^19.0.0"
60
58
  },
61
59
  "dependencies": {
62
60
  "@types/lodash-es": "^4.17.12",
63
- "laravel-precognition": "^1.0.2",
61
+ "laravel-precognition": "2.0.0-beta.3",
64
62
  "lodash-es": "^4.17.23",
65
- "@inertiajs/core": "2.3.17"
63
+ "@inertiajs/core": "3.0.0-beta.2"
66
64
  },
67
65
  "scripts": {
68
66
  "build": "pnpm clean && ./build.js && tsc",
@@ -71,6 +69,6 @@
71
69
  "dev": "pnpx concurrently -c \"#ffcf00,#3178c6\" \"pnpm dev:build\" \"pnpm dev:types\" --names build,types",
72
70
  "dev:build": "./build.js --watch",
73
71
  "dev:types": "tsc --watch --preserveWatchOutput",
74
- "es2020-check": "pnpm build:with-deps && es-check es2020 \"dist/index.esm.js\" --checkFeatures --module --noCache --verbose"
72
+ "es2020-check": "pnpm build:with-deps && es-check es2020 \"dist/index.js\" --checkFeatures --module --noCache --verbose"
75
73
  }
76
74
  }
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: inertia-react-development
3
- description: "Develops Inertia.js v2 React client-side applications. Activates when creating React pages, forms, or navigation; using <Link>, <Form>, useForm, or router; working with deferred props, prefetching, or polling; or when user mentions React with Inertia, React pages, React forms, or React navigation."
3
+ description: "Develops Inertia.js v3 React client-side applications. Activates when creating React pages, forms, or navigation; using <Link>, <Form>, useForm, useHttp, useLayoutProps, or router; working with deferred props, prefetching, optimistic updates, instant visits, or polling; or when user mentions React with Inertia, React pages, React forms, or React navigation."
4
4
  license: MIT
5
5
  metadata:
6
6
  author: laravel
@@ -15,14 +15,14 @@ metadata:
15
15
  Activate this skill when:
16
16
 
17
17
  - Creating or modifying React page components for Inertia
18
- - Working with forms in React (using `<Form>` or `useForm`)
18
+ - Working with forms in React (using `<Form>`, `useForm`, or `useHttp`)
19
19
  - Implementing client-side navigation with `<Link>` or `router`
20
- - Using v2 features: deferred props, prefetching, WhenVisible, InfiniteScroll, once props, flash data, or polling
20
+ - Using v3 features: deferred props, prefetching, optimistic updates, instant visits, layout props, HTTP requests, WhenVisible, InfiniteScroll, once props, flash data, or polling
21
21
  - Building React-specific features with the Inertia protocol
22
22
 
23
23
  ## Documentation
24
24
 
25
- Use `search-docs` for detailed Inertia v2 React patterns and documentation.
25
+ Use `search-docs` for detailed Inertia v3 React patterns and documentation.
26
26
 
27
27
  ## Basic Usage
28
28
 
@@ -267,7 +267,127 @@ export default function CreateUser() {
267
267
  }
268
268
  @endboostsnippet
269
269
 
270
- ## Inertia v2 Features
270
+ ## Inertia v3 Features
271
+
272
+ ### HTTP Requests
273
+
274
+ Use the `useHttp` hook for standalone HTTP requests that do not trigger Inertia page visits. It provides the same developer experience as `useForm`, but for plain JSON endpoints.
275
+
276
+ @boostsnippet("useHttp Example", "react")
277
+ import { useHttp } from '@inertiajs/react'
278
+
279
+ export default function Search() {
280
+ const { data, setData, get, processing } = useHttp({
281
+ query: '',
282
+ })
283
+
284
+ function search(e) {
285
+ setData('query', e.target.value)
286
+ get('/api/search', {
287
+ onSuccess: (response) => {
288
+ console.log(response)
289
+ },
290
+ })
291
+ }
292
+
293
+ return (
294
+ <>
295
+ <input value={data.query} onChange={search} />
296
+ {processing && <div>Searching...</div>}
297
+ </>
298
+ )
299
+ }
300
+ @endboostsnippet
301
+
302
+ ### Optimistic Updates
303
+
304
+ Apply data changes instantly before the server responds, with automatic rollback on failure:
305
+
306
+ @boostsnippet("Optimistic Update with Router", "react")
307
+ import { router } from '@inertiajs/react'
308
+
309
+ function like(post) {
310
+ router.optimistic((props) => ({
311
+ post: {
312
+ ...props.post,
313
+ likes: props.post.likes + 1,
314
+ },
315
+ })).post(`/posts/${post.id}/like`)
316
+ }
317
+ @endboostsnippet
318
+
319
+ Optimistic updates also work with `useForm` and the `<Form>` component:
320
+
321
+ @boostsnippet("Optimistic Update with Form Component", "react")
322
+ import { Form } from '@inertiajs/react'
323
+
324
+ <Form
325
+ action="/todos"
326
+ method="post"
327
+ optimistic={(props, data) => ({
328
+ todos: [...props.todos, { id: Date.now(), name: data.name, done: false }],
329
+ })}
330
+ >
331
+ <input type="text" name="name" />
332
+ <button type="submit">Add Todo</button>
333
+ </Form>
334
+ @endboostsnippet
335
+
336
+ ### Instant Visits
337
+
338
+ Navigate to a new page immediately without waiting for the server response. The target component renders right away with shared props, while page-specific props load in the background.
339
+
340
+ @verbatim
341
+ @boostsnippet("Instant Visit with Link", "react")
342
+ import { Link } from '@inertiajs/react'
343
+
344
+ <Link href="/dashboard" component="Dashboard">Dashboard</Link>
345
+
346
+ <Link
347
+ href="/posts/1"
348
+ component="Posts/Show"
349
+ pageProps={{ post: { id: 1, title: 'My Post' } }}
350
+ >
351
+ View Post
352
+ </Link>
353
+ @endboostsnippet
354
+ @endverbatim
355
+
356
+ ### Layout Props
357
+
358
+ Share dynamic data between pages and persistent layouts:
359
+
360
+ @boostsnippet("Layout Props in Layout", "react")
361
+ import { useLayoutProps } from '@inertiajs/react'
362
+
363
+ export default function Layout({ children }) {
364
+ const { title, showSidebar } = useLayoutProps({
365
+ title: 'My App',
366
+ showSidebar: true,
367
+ })
368
+
369
+ return (
370
+ <>
371
+ <header>{title}</header>
372
+ {showSidebar && <aside>Sidebar</aside>}
373
+ <main>{children}</main>
374
+ </>
375
+ )
376
+ }
377
+ @endboostsnippet
378
+
379
+ @boostsnippet("Setting Layout Props from Page", "react")
380
+ import { setLayoutProps } from '@inertiajs/react'
381
+
382
+ export default function Dashboard() {
383
+ setLayoutProps({
384
+ title: 'Dashboard',
385
+ showSidebar: false,
386
+ })
387
+
388
+ return <h1>Dashboard</h1>
389
+ }
390
+ @endboostsnippet
271
391
 
272
392
  ### Deferred Props
273
393
 
@@ -275,7 +395,6 @@ Use deferred props to load data after initial page render:
275
395
 
276
396
  @boostsnippet("Deferred Props with Empty State", "react")
277
397
  export default function UsersIndex({ users }) {
278
- // users will be undefined initially, then populated
279
398
  return (
280
399
  <div>
281
400
  <h1>Users</h1>
@@ -308,7 +427,7 @@ export default function Dashboard({ stats }) {
308
427
  useEffect(() => {
309
428
  const interval = setInterval(() => {
310
429
  router.reload({ only: ['stats'] })
311
- }, 5000) // Poll every 5 seconds
430
+ }, 5000)
312
431
 
313
432
  return () => clearInterval(interval)
314
433
  }, [])
@@ -334,7 +453,6 @@ export default function Dashboard({ stats }) {
334
453
  <div>
335
454
  <h1>Dashboard</h1>
336
455
 
337
- {/* stats prop is loaded only when this section scrolls into view */}
338
456
  <WhenVisible data="stats" buffer={200} fallback={<div className="animate-pulse">Loading stats...</div>}>
339
457
  {({ fetching }) => (
340
458
  <div>
@@ -360,3 +478,5 @@ Server-side patterns (Inertia::render, props, middleware) are covered in inertia
360
478
  - Not handling the `undefined` state of deferred props before data loads
361
479
  - Using `<form>` without preventing default submission (use `<Form>` component or `e.preventDefault()`)
362
480
  - Forgetting to check if `<Form>` component is available in your Inertia version
481
+ - Using `router.cancel()` instead of `router.cancelAll()` (v3 breaking change)
482
+ - Using `router.on('invalid', ...)` or `router.on('exception', ...)` instead of the renamed `httpException` and `networkError` events
package/types/App.d.ts CHANGED
@@ -9,12 +9,13 @@ export interface InertiaAppProps<SharedProps extends PageProps = PageProps> {
9
9
  }) => ReactNode;
10
10
  initialPage: Page<SharedProps>;
11
11
  initialComponent?: ReactComponent;
12
- resolveComponent?: (name: string) => ReactComponent | Promise<ReactComponent>;
12
+ resolveComponent?: (name: string, page?: Page) => ReactComponent | Promise<ReactComponent>;
13
13
  titleCallback?: HeadManagerTitleCallback;
14
14
  onHeadUpdate?: HeadManagerOnUpdateCallback;
15
+ defaultLayout?: (name: string, page: Page) => unknown;
15
16
  }
16
17
  export type InertiaApp = FunctionComponent<InertiaAppProps>;
17
- declare function App<SharedProps extends PageProps = PageProps>({ children, initialPage, initialComponent, resolveComponent, titleCallback, onHeadUpdate, }: InertiaAppProps<SharedProps>): import("react").FunctionComponentElement<import("react").ProviderProps<import("@inertiajs/core").HeadManager | null>>;
18
+ declare function App<SharedProps extends PageProps = PageProps>({ children, initialPage, initialComponent, resolveComponent, titleCallback, onHeadUpdate, defaultLayout, }: InertiaAppProps<SharedProps>): import("react").FunctionComponentElement<import("react").ProviderProps<import("@inertiajs/core").HeadManager | null>>;
18
19
  declare namespace App {
19
20
  var displayName: string;
20
21
  }
@@ -1,6 +1,9 @@
1
1
  import { ReactNode } from 'react';
2
+ interface DeferredSlotProps {
3
+ reloading: boolean;
4
+ }
2
5
  interface DeferredProps {
3
- children: ReactNode | (() => ReactNode);
6
+ children: ReactNode | ((props: DeferredSlotProps) => ReactNode);
4
7
  fallback: ReactNode | (() => ReactNode);
5
8
  data: string | string[];
6
9
  }
package/types/Form.d.ts CHANGED
@@ -1,20 +1,11 @@
1
- import { FormComponentRef, FormComponentSlotProps, FormDataConvertible, Method } from '@inertiajs/core';
1
+ import { FormComponentProps, FormComponentRef, FormComponentSlotProps } from '@inertiajs/core';
2
2
  import React, { ReactNode } from 'react';
3
- declare const Form: React.ForwardRefExoticComponent<Partial<Pick<import("@inertiajs/core").Visit<import("@inertiajs/core").RequestPayload>, "headers" | "errorBag" | "queryStringArrayFormat" | "showProgress" | "invalidateCacheTags"> & Omit<import("@inertiajs/core").VisitCallbacks<import("@inertiajs/core").RequestPayload>, "onPrefetched" | "onPrefetching">> & {
4
- method?: Method | Uppercase<Method>;
5
- action?: string | import("@inertiajs/core").UrlMethodPair;
6
- transform?: (data: Record<string, FormDataConvertible>) => Record<string, FormDataConvertible>;
7
- options?: import("@inertiajs/core").FormComponentOptions;
8
- onSubmitComplete?: (props: import("@inertiajs/core").FormComponentonSubmitCompleteArguments) => void;
9
- disableWhileProcessing?: boolean;
10
- resetOnSuccess?: boolean | string[];
11
- resetOnError?: boolean | string[];
12
- setDefaultsOnSuccess?: boolean;
13
- validateFiles?: boolean;
14
- validationTimeout?: number;
15
- withAllErrors?: boolean | null;
16
- } & Omit<React.FormHTMLAttributes<HTMLFormElement>, "children" | "method" | "headers" | "errorBag" | "queryStringArrayFormat" | "showProgress" | "invalidateCacheTags" | "onCancelToken" | "onBefore" | "onBeforeUpdate" | "onStart" | "onProgress" | "onFinish" | "onCancel" | "onSuccess" | "onError" | "onFlash" | "withAllErrors" | "options" | "action" | "transform" | "onSubmitComplete" | "disableWhileProcessing" | "resetOnSuccess" | "resetOnError" | "setDefaultsOnSuccess" | "validateFiles" | "validationTimeout"> & Omit<React.AllHTMLAttributes<HTMLFormElement>, "children" | "method" | "headers" | "errorBag" | "queryStringArrayFormat" | "showProgress" | "invalidateCacheTags" | "onCancelToken" | "onBefore" | "onBeforeUpdate" | "onStart" | "onProgress" | "onFinish" | "onCancel" | "onSuccess" | "onError" | "onFlash" | "withAllErrors" | "options" | "action" | "transform" | "onSubmitComplete" | "disableWhileProcessing" | "resetOnSuccess" | "resetOnError" | "setDefaultsOnSuccess" | "validateFiles" | "validationTimeout"> & {
17
- children: ReactNode | ((props: FormComponentSlotProps) => ReactNode);
18
- } & React.RefAttributes<FormComponentSlotProps>>;
19
- export declare function useFormContext(): FormComponentRef | undefined;
20
- export default Form;
3
+ type FormProps<TForm extends object = Record<string, any>> = FormComponentProps & Omit<React.FormHTMLAttributes<HTMLFormElement>, keyof FormComponentProps | 'children'> & Omit<React.AllHTMLAttributes<HTMLFormElement>, keyof FormComponentProps | 'children'> & {
4
+ children: ReactNode | ((props: FormComponentSlotProps<TForm>) => ReactNode);
5
+ };
6
+ export declare function useFormContext<TForm extends object = Record<string, any>>(): FormComponentRef<TForm> | undefined;
7
+ declare const _default: {
8
+ <TForm extends object = Record<string, any>>(props: FormProps<TForm> & React.RefAttributes<FormComponentRef<TForm>>): React.ReactElement;
9
+ displayName: string;
10
+ };
11
+ export default _default;
@@ -1,4 +1,4 @@
1
- import { InfiniteScrollActionSlotProps, InfiniteScrollComponentBaseProps, InfiniteScrollRef, InfiniteScrollSlotProps } from '@inertiajs/core';
1
+ import { InfiniteScrollActionSlotProps, InfiniteScrollComponentBaseProps, InfiniteScrollRef, InfiniteScrollSlotProps, ReloadOptions } from '@inertiajs/core';
2
2
  import React from 'react';
3
3
  interface ComponentProps extends InfiniteScrollComponentBaseProps, Omit<React.HTMLAttributes<HTMLElement>, keyof InfiniteScrollComponentBaseProps | 'children'> {
4
4
  children?: React.ReactNode | ((props: InfiniteScrollSlotProps) => React.ReactNode);
@@ -8,6 +8,7 @@ interface ComponentProps extends InfiniteScrollComponentBaseProps, Omit<React.HT
8
8
  previous?: React.ReactNode | ((props: InfiniteScrollActionSlotProps) => React.ReactNode);
9
9
  next?: React.ReactNode | ((props: InfiniteScrollActionSlotProps) => React.ReactNode);
10
10
  loading?: React.ReactNode | ((props: InfiniteScrollActionSlotProps) => React.ReactNode);
11
+ params?: ReloadOptions;
11
12
  onlyNext?: boolean;
12
13
  onlyPrevious?: boolean;
13
14
  }
@@ -1,4 +1,4 @@
1
- import { CreateInertiaAppOptionsForCSR, CreateInertiaAppOptionsForSSR, InertiaAppSSRResponse, PageProps } from '@inertiajs/core';
1
+ import { CreateInertiaAppOptions, CreateInertiaAppOptionsForCSR, CreateInertiaAppOptionsForSSR, InertiaAppSSRResponse, Page, PageProps } from '@inertiajs/core';
2
2
  import { ReactElement } from 'react';
3
3
  import { renderToString } from 'react-dom/server';
4
4
  import { InertiaAppProps, type InertiaApp } from './App';
@@ -8,13 +8,24 @@ export type SetupOptions<ElementType, SharedProps extends PageProps> = {
8
8
  App: InertiaApp;
9
9
  props: InertiaAppProps<SharedProps>;
10
10
  };
11
- type ComponentResolver = (name: string) => ReactComponent | Promise<ReactComponent> | {
11
+ type ComponentResolver = (name: string, page?: Page) => ReactComponent | Promise<ReactComponent> | {
12
12
  default: ReactComponent;
13
- } | unknown;
14
- type InertiaAppOptionsForCSR<SharedProps extends PageProps> = CreateInertiaAppOptionsForCSR<SharedProps, ComponentResolver, SetupOptions<HTMLElement, SharedProps>, void, ReactInertiaAppConfig>;
13
+ };
14
+ type InertiaAppOptionsForCSR<SharedProps extends PageProps> = CreateInertiaAppOptionsForCSR<SharedProps, ComponentResolver, SetupOptions<HTMLElement, SharedProps>, void, ReactInertiaAppConfig> & {
15
+ strictMode?: undefined;
16
+ };
15
17
  type InertiaAppOptionsForSSR<SharedProps extends PageProps> = CreateInertiaAppOptionsForSSR<SharedProps, ComponentResolver, SetupOptions<null, SharedProps>, ReactElement, ReactInertiaAppConfig> & {
16
18
  render: typeof renderToString;
19
+ strictMode?: undefined;
20
+ };
21
+ type InertiaAppOptionsAuto<SharedProps extends PageProps> = CreateInertiaAppOptions<ComponentResolver, SetupOptions<HTMLElement | null, SharedProps>, ReactElement | void, ReactInertiaAppConfig> & {
22
+ page?: Page<SharedProps>;
23
+ render?: undefined;
24
+ strictMode?: boolean;
17
25
  };
26
+ type RenderToString = (element: ReactElement) => string;
27
+ type RenderFunction<SharedProps extends PageProps> = (page: Page<SharedProps>, renderToString: RenderToString) => Promise<InertiaAppSSRResponse>;
18
28
  export default function createInertiaApp<SharedProps extends PageProps = PageProps>(options: InertiaAppOptionsForCSR<SharedProps>): Promise<void>;
19
29
  export default function createInertiaApp<SharedProps extends PageProps = PageProps>(options: InertiaAppOptionsForSSR<SharedProps>): Promise<InertiaAppSSRResponse>;
30
+ export default function createInertiaApp<SharedProps extends PageProps = PageProps>(options?: InertiaAppOptionsAuto<SharedProps>): Promise<void | RenderFunction<SharedProps>>;
20
31
  export {};
package/types/index.d.ts CHANGED
@@ -1,28 +1,19 @@
1
- export declare const progress: {
2
- hideCount: number;
3
- start(): void;
4
- reveal(force?: boolean): void;
5
- hide(): void;
6
- set(status: number): void;
7
- finish(): void;
8
- reset(): void;
9
- remove(): void;
10
- isStarted(): boolean;
11
- getStatus(): number | null;
12
- };
13
- export declare const router: import("@inertiajs/core").Router;
1
+ import type { ReactInertiaAppConfig } from './types';
2
+ export { http, progress, router } from '@inertiajs/core';
14
3
  export { default as App } from './App';
15
4
  export { default as createInertiaApp } from './createInertiaApp';
16
5
  export { default as Deferred } from './Deferred';
17
6
  export { default as Form, useFormContext } from './Form';
18
7
  export { default as Head } from './Head';
19
8
  export { default as InfiniteScroll } from './InfiniteScroll';
9
+ export { resetLayoutProps, setLayoutProps, setLayoutPropsFor, useLayoutProps } from './layoutProps';
20
10
  export { InertiaLinkProps, default as Link } from './Link';
21
11
  export { ReactComponent as ResolvedComponent } from './types';
22
- export { InertiaFormProps, InertiaPrecognitiveFormProps, SetDataAction, SetDataByKeyValuePair, SetDataByMethod, SetDataByObject, default as useForm, } from './useForm';
12
+ export { InertiaForm, InertiaFormProps, InertiaPrecognitiveFormProps, SetDataAction, SetDataByKeyValuePair, SetDataByMethod, SetDataByObject, default as useForm, } from './useForm';
13
+ export { default as useHttp } from './useHttp';
23
14
  export { default as usePage } from './usePage';
24
15
  export { default as usePoll } from './usePoll';
25
16
  export { default as usePrefetch } from './usePrefetch';
26
17
  export { default as useRemember } from './useRemember';
27
18
  export { default as WhenVisible } from './WhenVisible';
28
- export declare const config: import("@inertiajs/core").Config<import("@inertiajs/core").InertiaAppConfig>;
19
+ export declare const config: import("@inertiajs/core").Config<import("@inertiajs/core").InertiaAppConfig & ReactInertiaAppConfig>;
@@ -0,0 +1,8 @@
1
+ export declare function setLayoutProps(props: Record<string, unknown>): void;
2
+ export declare function setLayoutPropsFor(name: string, props: Record<string, unknown>): void;
3
+ export declare function resetLayoutProps(): void;
4
+ export declare const LayoutPropsContext: import("react").Context<{
5
+ staticProps: Record<string, unknown>;
6
+ name?: string;
7
+ }>;
8
+ export declare function useLayoutProps<T extends Record<string, unknown>>(defaults: T): T;
package/types/react.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  import { DependencyList, EffectCallback } from 'react';
2
2
  export declare function useIsomorphicLayoutEffect(effect: EffectCallback, deps?: DependencyList): void;
3
- export declare const isReact19: boolean;
package/types/types.d.ts CHANGED
@@ -8,4 +8,6 @@ export type ReactComponent = ComponentType<any> & {
8
8
  layout?: LayoutComponent | LayoutComponent[] | LayoutFunction;
9
9
  };
10
10
  export type ReactPageHandlerArgs = Parameters<PageHandler<ComponentType>>[0];
11
- export type ReactInertiaAppConfig = {};
11
+ export type ReactInertiaAppConfig = {
12
+ strictMode?: boolean;
13
+ };
@@ -1,13 +1,11 @@
1
- import { ErrorValue, FormDataErrors, FormDataKeys, FormDataType, FormDataValues, Method, Progress, UrlMethodPair, UseFormSubmitArguments, UseFormSubmitOptions, UseFormTransformCallback, UseFormWithPrecognitionArguments } from '@inertiajs/core';
2
- import { NamedInputEvent, PrecognitionPath, ValidationConfig, Validator } from 'laravel-precognition';
3
- export type SetDataByObject<TForm> = (data: Partial<TForm>) => void;
4
- export type SetDataByMethod<TForm> = (data: (previousData: TForm) => TForm) => void;
5
- export type SetDataByKeyValuePair<TForm> = <K extends FormDataKeys<TForm>>(key: K, value: FormDataValues<TForm, K>) => void;
6
- export type SetDataAction<TForm extends Record<any, any>> = SetDataByObject<TForm> & SetDataByMethod<TForm> & SetDataByKeyValuePair<TForm>;
1
+ import { ErrorValue, FormDataErrors, FormDataKeys, FormDataType, FormDataValues, Method, OptimisticCallback, Progress, UrlMethodPair, UseFormSubmitArguments, UseFormSubmitOptions, UseFormTransformCallback, UseFormWithPrecognitionArguments } from '@inertiajs/core';
2
+ import type { NamedInputEvent, PrecognitionPath, ValidationConfig, Validator } from 'laravel-precognition';
3
+ import { SetDataAction, SetDataByKeyValuePair, SetDataByMethod, SetDataByObject } from './useFormState';
4
+ export { SetDataAction, SetDataByKeyValuePair, SetDataByMethod, SetDataByObject };
7
5
  type PrecognitionValidationConfig<TKeys> = ValidationConfig & {
8
6
  only?: TKeys[] | Iterable<TKeys> | ArrayLike<TKeys>;
9
7
  };
10
- export interface InertiaFormProps<TForm extends object> {
8
+ export interface InertiaFormProps<TForm extends Record<string, any>> {
11
9
  data: TForm;
12
10
  isDirty: boolean;
13
11
  errors: FormDataErrors<TForm>;
@@ -32,15 +30,16 @@ export interface InertiaFormProps<TForm extends object> {
32
30
  };
33
31
  submit: (...args: UseFormSubmitArguments) => void;
34
32
  get: (url: string, options?: UseFormSubmitOptions) => void;
35
- patch: (url: string, options?: UseFormSubmitOptions) => void;
36
33
  post: (url: string, options?: UseFormSubmitOptions) => void;
37
34
  put: (url: string, options?: UseFormSubmitOptions) => void;
35
+ patch: (url: string, options?: UseFormSubmitOptions) => void;
38
36
  delete: (url: string, options?: UseFormSubmitOptions) => void;
39
37
  cancel: () => void;
40
38
  dontRemember: <K extends FormDataKeys<TForm>>(...fields: K[]) => InertiaFormProps<TForm>;
39
+ optimistic: <TProps>(callback: OptimisticCallback<TProps>) => InertiaFormProps<TForm>;
41
40
  withPrecognition: (...args: UseFormWithPrecognitionArguments) => InertiaPrecognitiveFormProps<TForm>;
42
41
  }
43
- export interface InertiaFormValidationProps<TForm extends object> {
42
+ export interface InertiaFormValidationProps<TForm extends Record<string, any>> {
44
43
  invalid: <K extends FormDataKeys<TForm>>(field: K) => boolean;
45
44
  setValidationTimeout: (duration: number) => InertiaPrecognitiveFormProps<TForm>;
46
45
  touch: <K extends FormDataKeys<TForm>>(field: K | NamedInputEvent | Array<K>, ...fields: K[]) => InertiaPrecognitiveFormProps<TForm>;
@@ -55,11 +54,10 @@ export interface InertiaFormValidationProps<TForm extends object> {
55
54
  setErrors: (errors: FormDataErrors<TForm>) => InertiaPrecognitiveFormProps<TForm>;
56
55
  forgetError: <K extends FormDataKeys<TForm> | NamedInputEvent>(field: K) => InertiaPrecognitiveFormProps<TForm>;
57
56
  }
58
- export type InertiaForm<TForm extends object> = InertiaFormProps<TForm>;
59
- export type InertiaPrecognitiveFormProps<TForm extends object> = InertiaFormProps<TForm> & InertiaFormValidationProps<TForm>;
57
+ export type InertiaForm<TForm extends Record<string, any>> = InertiaFormProps<TForm>;
58
+ export type InertiaPrecognitiveFormProps<TForm extends Record<string, any>> = InertiaFormProps<TForm> & InertiaFormValidationProps<TForm>;
60
59
  export default function useForm<TForm extends FormDataType<TForm>>(method: Method | (() => Method), url: string | (() => string), data: TForm | (() => TForm)): InertiaPrecognitiveFormProps<TForm>;
61
60
  export default function useForm<TForm extends FormDataType<TForm>>(urlMethodPair: UrlMethodPair | (() => UrlMethodPair), data: TForm | (() => TForm)): InertiaPrecognitiveFormProps<TForm>;
62
61
  export default function useForm<TForm extends FormDataType<TForm>>(rememberKey: string, data: TForm | (() => TForm)): InertiaFormProps<TForm>;
63
62
  export default function useForm<TForm extends FormDataType<TForm>>(data: TForm | (() => TForm)): InertiaFormProps<TForm>;
64
63
  export default function useForm<TForm extends FormDataType<TForm>>(): InertiaFormProps<TForm>;
65
- export {};
@@ -0,0 +1,79 @@
1
+ import { ErrorValue, FormDataErrors, FormDataKeys, FormDataValues, Progress, UrlMethodPair, UseFormTransformCallback, UseFormWithPrecognitionArguments } from '@inertiajs/core';
2
+ import { NamedInputEvent, ValidationConfig, Validator } from 'laravel-precognition';
3
+ export type SetDataByObject<TForm> = (data: Partial<TForm>) => void;
4
+ export type SetDataByMethod<TForm> = (data: (previousData: TForm) => TForm) => void;
5
+ export type SetDataByKeyValuePair<TForm> = <K extends FormDataKeys<TForm>>(key: K, value: FormDataValues<TForm, K>) => void;
6
+ export type SetDataAction<TForm extends Record<any, any>> = SetDataByObject<TForm> & SetDataByMethod<TForm> & SetDataByKeyValuePair<TForm>;
7
+ type PrecognitionValidationConfig<TKeys> = ValidationConfig & {
8
+ only?: TKeys[] | Iterable<TKeys> | ArrayLike<TKeys>;
9
+ };
10
+ export interface FormStateProps<TForm extends object> {
11
+ data: TForm;
12
+ isDirty: boolean;
13
+ errors: FormDataErrors<TForm>;
14
+ hasErrors: boolean;
15
+ processing: boolean;
16
+ progress: Progress | null;
17
+ wasSuccessful: boolean;
18
+ recentlySuccessful: boolean;
19
+ setData: SetDataAction<TForm>;
20
+ transform: (callback: UseFormTransformCallback<TForm>) => void;
21
+ setDefaults: {
22
+ (): void;
23
+ <T extends FormDataKeys<TForm>>(field: T, value: FormDataValues<TForm, T>): void;
24
+ (fields: Partial<TForm>): void;
25
+ };
26
+ reset: <K extends FormDataKeys<TForm>>(...fields: K[]) => void;
27
+ clearErrors: <K extends FormDataKeys<TForm>>(...fields: K[]) => void;
28
+ resetAndClearErrors: <K extends FormDataKeys<TForm>>(...fields: K[]) => void;
29
+ setError: {
30
+ <K extends FormDataKeys<TForm>>(field: K, value: ErrorValue): void;
31
+ (errors: FormDataErrors<TForm>): void;
32
+ };
33
+ withPrecognition: (...args: UseFormWithPrecognitionArguments) => FormStateWithPrecognition<TForm>;
34
+ }
35
+ export interface FormStateValidationProps<TForm extends object> {
36
+ invalid: <K extends FormDataKeys<TForm>>(field: K) => boolean;
37
+ setValidationTimeout: (duration: number) => FormStateWithPrecognition<TForm>;
38
+ touch: <K extends FormDataKeys<TForm>>(field: K | NamedInputEvent | Array<K>, ...fields: K[]) => FormStateWithPrecognition<TForm>;
39
+ touched: <K extends FormDataKeys<TForm>>(field?: K) => boolean;
40
+ valid: <K extends FormDataKeys<TForm>>(field: K) => boolean;
41
+ validate: <K extends FormDataKeys<TForm>>(field?: K | NamedInputEvent | PrecognitionValidationConfig<K>, config?: PrecognitionValidationConfig<K>) => FormStateWithPrecognition<TForm>;
42
+ validateFiles: () => FormStateWithPrecognition<TForm>;
43
+ validating: boolean;
44
+ validator: () => Validator;
45
+ withAllErrors: () => FormStateWithPrecognition<TForm>;
46
+ withoutFileValidation: () => FormStateWithPrecognition<TForm>;
47
+ setErrors: (errors: FormDataErrors<TForm>) => FormStateWithPrecognition<TForm>;
48
+ forgetError: <K extends FormDataKeys<TForm> | NamedInputEvent>(field: K) => FormStateWithPrecognition<TForm>;
49
+ }
50
+ export type FormState<TForm extends object> = FormStateProps<TForm>;
51
+ export type FormStateWithPrecognition<TForm extends object> = FormStateProps<TForm> & FormStateValidationProps<TForm>;
52
+ export interface UseFormStateOptions<TForm extends object> {
53
+ data: TForm | (() => TForm);
54
+ precognitionEndpoint?: (() => UrlMethodPair) | null;
55
+ useDataState?: () => [TForm, React.Dispatch<React.SetStateAction<TForm>>];
56
+ useErrorsState?: () => [FormDataErrors<TForm>, React.Dispatch<React.SetStateAction<FormDataErrors<TForm>>>];
57
+ }
58
+ export interface UseFormStateReturn<TForm extends object> {
59
+ form: FormState<TForm>;
60
+ setDefaultsState: React.Dispatch<React.SetStateAction<TForm>>;
61
+ transformRef: React.MutableRefObject<UseFormTransformCallback<TForm>>;
62
+ precognitionEndpointRef: React.MutableRefObject<(() => UrlMethodPair) | null>;
63
+ dataRef: React.MutableRefObject<TForm>;
64
+ isMounted: React.MutableRefObject<boolean>;
65
+ setProcessing: React.Dispatch<React.SetStateAction<boolean>>;
66
+ setProgress: React.Dispatch<React.SetStateAction<Progress | null>>;
67
+ markAsSuccessful: () => void;
68
+ clearErrors: (...fields: string[]) => void;
69
+ setError: (fieldOrFields: FormDataKeys<TForm> | FormDataErrors<TForm>, maybeValue?: ErrorValue) => void;
70
+ defaultsCalledInOnSuccessRef: React.MutableRefObject<boolean>;
71
+ resetBeforeSubmit: () => void;
72
+ finishProcessing: () => void;
73
+ withAllErrors: {
74
+ enabled: () => boolean;
75
+ enable: () => void;
76
+ };
77
+ }
78
+ export default function useFormState<TForm extends object>(options: UseFormStateOptions<TForm>): UseFormStateReturn<TForm>;
79
+ export {};