Skip to content

Commit 54c22b6

Browse files
authored
Merge pull request #4 from lifespikes/feature/inertia-v1
feature: adding support to inertia v1
2 parents 08a9bfe + f700385 commit 54c22b6

File tree

6 files changed

+60
-40
lines changed

6 files changed

+60
-40
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ npm i @lifespikes/laravel-precognition-react
2121
#### Using Yarn
2222

2323
```bash
24-
yarn @lifespikes/laravel-precognition-react
24+
yarn add @lifespikes/laravel-precognition-react
2525
```
2626

2727
#### Using pnpm
2828

2929
```bash
30-
pnpm @lifespikes/laravel-precognition-react
30+
pnpm add @lifespikes/laravel-precognition-react
3131
```
3232

3333
# Usage

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lifespikes/laravel-precognition-react",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "A set of React Hooks for Laravel Precognition",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -50,7 +50,6 @@
5050
}
5151
],
5252
"devDependencies": {
53-
"@inertiajs/inertia": "^0.11.1",
5453
"@size-limit/preset-small-lib": "^8.1.0",
5554
"@types/react": "^18.0.26",
5655
"@typescript-eslint/eslint-plugin": "^5.46.0",
@@ -68,7 +67,7 @@
6867
"typescript": "^4.9.4"
6968
},
7069
"dependencies": {
71-
"@inertiajs/inertia-react": "^0.8.1",
70+
"@inertiajs/react": "^1.0.0",
7271
"laravel-precognition": "^0.1.0"
7372
},
7473
"bugs": {

src/helpers/patchInertiaForm.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {
44
ValidationErrors,
55
Validator,
66
} from 'laravel-precognition/dist/types';
7-
import { InertiaFormProps } from '@inertiajs/inertia-react';
87
import { toSimpleValidationErrors } from 'laravel-precognition';
9-
import { Method, VisitOptions } from '@inertiajs/inertia';
8+
import { InertiaFormProps } from '@inertiajs/react/types/useForm';
9+
import { VisitOptions, Method } from '@inertiajs/core/types/types';
1010

1111
const getOptionsWithValidator = (
1212
validator: Validator,
@@ -26,7 +26,7 @@ const getOptionsWithValidator = (
2626
};
2727
};
2828

29-
export const patchInertiaForm = <TForm = Record<string, any>>(
29+
export const patchInertiaForm = <TForm extends Record<string, unknown>>(
3030
method: RequestMethods,
3131
url: string,
3232
form: InertiaFormProps<TForm>,

src/hooks/useInertiaPrecognitionForm.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useForm } from '@inertiajs/inertia-react';
1+
import { useForm } from '@inertiajs/react';
22
import { useMemo } from 'react';
33
import {
44
UseInertiaPrecognitionFormReturn,
@@ -7,7 +7,9 @@ import {
77
import { usePrecognition } from './usePrecognition';
88
import { patchInertiaForm } from '../helpers/patchInertiaForm';
99

10-
export function useInertiaPrecognitionForm<TForm = Record<string, any>>({
10+
export function useInertiaPrecognitionForm<
11+
TForm extends Record<string, unknown>
12+
>({
1113
precognition: { method, url, config },
1214
form: { initialValues },
1315
}: UsePrecognitionFormProps<TForm>): UseInertiaPrecognitionFormReturn<TForm> {

src/types/hooks.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
Validator,
66
} from 'laravel-precognition/dist/types';
77
import { Dispatch, SetStateAction } from 'react';
8-
import { InertiaFormProps } from '@inertiajs/inertia-react';
8+
import { InertiaFormProps } from '@inertiajs/react/types/useForm';
99

1010
export type UsePrecognitionFormProps<TForm = Record<string, any>> = {
1111
precognition: {
@@ -31,11 +31,13 @@ export type UsePrecognitionReturn<TForm = Record<string, any>> = {
3131
setValidatorTimeout(duration: Timeout): UsePrecognitionReturn<TForm>;
3232
};
3333

34-
export type InertiaPrecognitionFormProps<TForm = Record<string, any>> =
35-
InertiaFormProps<TForm> & UsePrecognitionReturn<TForm>;
34+
export type InertiaPrecognitionFormProps<
35+
TForm extends Record<string, unknown>
36+
> = InertiaFormProps<TForm> & UsePrecognitionReturn<TForm>;
3637

37-
export interface UseInertiaPrecognitionFormReturn<TForm = Record<string, any>>
38-
extends InertiaPrecognitionFormProps<TForm> {
38+
export interface UseInertiaPrecognitionFormReturn<
39+
TForm extends Record<string, unknown>
40+
> extends InertiaPrecognitionFormProps<TForm> {
3941
validateAndSetDataByKeyValuePair(
4042
name: keyof TForm,
4143
value: any
@@ -46,11 +48,9 @@ export interface UseInertiaPrecognitionFormReturn<TForm = Record<string, any>>
4648
export type UsePrecognitionFormReturn<TForm = Record<string, any>> =
4749
UsePrecognitionReturn<TForm> & {
4850
data: TForm;
49-
setData: React.Dispatch<React.SetStateAction<TForm>>;
51+
setData: Dispatch<SetStateAction<TForm>>;
5052
errors: Record<keyof TForm, string> | null;
51-
setErrors: React.Dispatch<
52-
React.SetStateAction<Record<keyof TForm, string> | null>
53-
>;
53+
setErrors: Dispatch<SetStateAction<Record<keyof TForm, string> | null>>;
5454
clearErrors: () => void;
5555
validateAndSetDataByKeyValuePair(
5656
key: keyof TForm,

yarn.lock

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -993,22 +993,24 @@
993993
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45"
994994
integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==
995995

996-
"@inertiajs/inertia-react@^0.8.1":
997-
version "0.8.1"
998-
resolved "https://registry.yarnpkg.com/@inertiajs/inertia-react/-/inertia-react-0.8.1.tgz#730e1f592086c8e97e21e3f4ed639cb952bcfd77"
999-
integrity sha512-9Uu7t4EA9FrcREwWnOU/qW5i4hYFt+uFn5cqP6RGJo8lJS4u8t6Q9358oHuQUKbFEbaIjUu7aslCL3/Istctlg==
1000-
dependencies:
1001-
lodash.isequal "^4.5.0"
1002-
1003-
"@inertiajs/inertia@^0.11.1":
1004-
version "0.11.1"
1005-
resolved "https://registry.yarnpkg.com/@inertiajs/inertia/-/inertia-0.11.1.tgz#f324f09a03e1dd944404bd09935c0141a4b3a85d"
1006-
integrity sha512-btmV53c54oW4Z9XF0YyTdIUnM7ue0ONy3/KJOz6J1C5CYIwimiKfDMpz8ZbGJuxS+SPdOlNsqj2ZhlHslpJRZg==
996+
"@inertiajs/[email protected]":
997+
version "1.0.0"
998+
resolved "https://registry.yarnpkg.com/@inertiajs/core/-/core-1.0.0.tgz#40e5b71d20ff0e6b5e7e2b5c9091b720e4600030"
999+
integrity sha512-V8GgUMqwD6L0A+/O5EEnoCKI/CJ6o33/PUlrjte2skAixZmuNjL3AcP1pB5xUPLMFxGONpZVU2BTpqTC2ppLGA==
10071000
dependencies:
1008-
axios "^0.21.1"
1001+
axios "^1.2.0"
10091002
deepmerge "^4.0.0"
1003+
nprogress "^0.2.0"
10101004
qs "^6.9.0"
10111005

1006+
"@inertiajs/react@^1.0.0":
1007+
version "1.0.0"
1008+
resolved "https://registry.yarnpkg.com/@inertiajs/react/-/react-1.0.0.tgz#dfd3ca3f1078fbc303df2876651d08f071e20222"
1009+
integrity sha512-oJnLjV1qw2zif5LRta3ota+pXbc8N7NZ8JeoYsJk/DeOlv6S/Yz6WZYGksVUu0zxcpoYeMZEZ3q7vxiq+0UhkA==
1010+
dependencies:
1011+
"@inertiajs/core" "1.0.0"
1012+
lodash.isequal "^4.5.0"
1013+
10121014
"@istanbuljs/load-nyc-config@^1.0.0":
10131015
version "1.1.0"
10141016
resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz#fd3db1d59ecf7cf121e80650bb86712f9b55eced"
@@ -1904,13 +1906,6 @@ axe-core@^4.4.3:
19041906
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.6.0.tgz#1d07514866fa51262734b3357932fcf86961383a"
19051907
integrity sha512-L3ZNbXPTxMrl0+qTXAzn9FBRvk5XdO56K8CvcCKtlxv44Aw2w2NCclGuvCWxHPw1Riiq3ncP/sxFYj2nUqdoTw==
19061908

1907-
axios@^0.21.1:
1908-
version "0.21.4"
1909-
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575"
1910-
integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==
1911-
dependencies:
1912-
follow-redirects "^1.14.0"
1913-
19141909
axios@^0.27.2:
19151910
version "0.27.2"
19161911
resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972"
@@ -1919,6 +1914,15 @@ axios@^0.27.2:
19191914
follow-redirects "^1.14.9"
19201915
form-data "^4.0.0"
19211916

1917+
axios@^1.2.0:
1918+
version "1.3.2"
1919+
resolved "https://registry.yarnpkg.com/axios/-/axios-1.3.2.tgz#7ac517f0fa3ec46e0e636223fd973713a09c72b3"
1920+
integrity sha512-1M3O703bYqYuPhbHeya5bnhpYVsDDRyQSabNja04mZtboLNSuZ4YrltestrLXfHgmzua4TpUqRiVKbiQuo2epw==
1921+
dependencies:
1922+
follow-redirects "^1.15.0"
1923+
form-data "^4.0.0"
1924+
proxy-from-env "^1.1.0"
1925+
19221926
axobject-query@^2.2.0:
19231927
version "2.2.0"
19241928
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be"
@@ -2536,7 +2540,12 @@ deep-is@^0.1.3, deep-is@~0.1.3:
25362540
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.4.tgz#a6f2dce612fadd2ef1f519b73551f17e85199831"
25372541
integrity sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==
25382542

2539-
deepmerge@^4.0.0, deepmerge@^4.2.2:
2543+
deepmerge@^4.0.0:
2544+
version "4.3.0"
2545+
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.3.0.tgz#65491893ec47756d44719ae520e0e2609233b59b"
2546+
integrity sha512-z2wJZXrmeHdvYJp/Ux55wIjqo81G5Bp4c+oELTW+7ar6SogWHajt5a9gO3s3IDaGSAXjDk0vlQKN3rms8ab3og==
2547+
2548+
deepmerge@^4.2.2:
25402549
version "4.2.2"
25412550
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955"
25422551
integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==
@@ -3470,7 +3479,7 @@ flatted@^3.1.0:
34703479
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787"
34713480
integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==
34723481

3473-
follow-redirects@^1.14.0, follow-redirects@^1.14.9:
3482+
follow-redirects@^1.14.9, follow-redirects@^1.15.0:
34743483
version "1.15.2"
34753484
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
34763485
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
@@ -5234,6 +5243,11 @@ npm-run-path@^4.0.0:
52345243
dependencies:
52355244
path-key "^3.0.0"
52365245

5246+
nprogress@^0.2.0:
5247+
version "0.2.0"
5248+
resolved "https://registry.yarnpkg.com/nprogress/-/nprogress-0.2.0.tgz#cb8f34c53213d895723fcbab907e9422adbcafb1"
5249+
integrity sha512-I19aIingLgR1fmhftnbWWO3dXc0hSxqHQHQb3H8m+K3TnEn/iSeTZZOyvKXWqQESMwuUVnatlCnZdLBZZt2VSA==
5250+
52375251
nwsapi@^2.2.0:
52385252
version "2.2.2"
52395253
resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.2.2.tgz#e5418863e7905df67d51ec95938d67bf801f0bb0"
@@ -5610,6 +5624,11 @@ prop-types@^15.8.1:
56105624
object-assign "^4.1.1"
56115625
react-is "^16.13.1"
56125626

5627+
proxy-from-env@^1.1.0:
5628+
version "1.1.0"
5629+
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
5630+
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
5631+
56135632
psl@^1.1.28:
56145633
version "1.9.0"
56155634
resolved "https://registry.yarnpkg.com/psl/-/psl-1.9.0.tgz#d0df2a137f00794565fcaf3b2c00cd09f8d5a5a7"

0 commit comments

Comments
 (0)