first commit

This commit is contained in:
Ariyutta
2026-08-07 10:47:09 +07:00
commit 1c094fbe7f
11630 changed files with 1580900 additions and 0 deletions
@@ -0,0 +1,45 @@
## Inertia v1 + React Forms
- For form handling in Inertia pages, use `router.post` and related methods. Do not use regular forms.
@verbatim
<code-snippet name="Inertia React Form Example" lang="react">
import { useState } from 'react'
import { router } from '@inertiajs/react'
export default function Edit() {
const [values, setValues] = useState({
first_name: "",
last_name: "",
email: "",
})
function handleChange(e) {
const key = e.target.id;
const value = e.target.value
setValues(values => ({
...values,
[key]: value,
}))
}
function handleSubmit(e) {
e.preventDefault()
router.post('/users', values)
}
return (
<form onSubmit={handleSubmit}>
<label htmlFor="first_name">First name:</label>
<input id="first_name" value={values.first_name} onChange={handleChange} />
<label htmlFor="last_name">Last name:</label>
<input id="last_name" value={values.last_name} onChange={handleChange} />
<label htmlFor="email">Email:</label>
<input id="email" value={values.email} onChange={handleChange} />
<button type="submit">Submit</button>
</form>
)
}
</code-snippet>
@endverbatim
@@ -0,0 +1,66 @@
@php
/** @var \Laravel\Boost\Install\GuidelineAssist $assist */
@endphp
## Inertia v2 + React Forms
@if($assist->inertia()->hasFormComponent())
@boostsnippet("`<Form>` Component Example", "react")
import { Form } from '@inertiajs/react'
export default () => (
<Form action="/users" method="post">
{({
errors,
hasErrors,
processing,
wasSuccessful,
recentlySuccessful,
clearErrors,
resetAndClearErrors,
defaults
}) => (
<>
<input type="text" name="name" />
{errors.name && <div>{errors.name}</div>}
<button type="submit" disabled={processing}>
{processing ? 'Creating...' : 'Create User'}
</button>
{wasSuccessful && <div>User created successfully!</div>}
</>
)}
</Form>
)
@endboostsnippet
@endif
@if($assist->inertia()->hasFormComponent() === false)
{{-- Inertia 2.0.x, not 2.1.0 or higher. So still need to use 'useForm' --}}
@boostsnippet("Inertia React useForm Example", "react")
import { useForm } from '@inertiajs/react'
const { data, setData, post, processing, errors } = useForm({
email: '',
password: '',
remember: false,
})
function submit(e) {
e.preventDefault()
post('/login')
}
return (
<form onSubmit={submit}>
<input type="text" value={data.email} onChange={e => setData('email', e.target.value)} />
{errors.email && <div>{errors.email}</div>}
<input type="password" value={data.password} onChange={e => setData('password', e.target.value)} />
{errors.password && <div>{errors.password}</div>}
<input type="checkbox" checked={data.remember} onChange={e => setData('remember', e.target.checked)} /> Remember Me
<button type="submit" disabled={processing}>Login</button>
</form>
)
@endboostsnippet
@endif
+8
View File
@@ -0,0 +1,8 @@
## Inertia + React
- Use `router.visit()` or `<Link>` for navigation instead of traditional links.
@boostsnippet("Inertia Client Navigation", "react")
import { Link } from '@inertiajs/react'
<Link href="/">Home</Link>
@endboostsnippet