Searching...
}
>
)
}
@endboostsnippet
### Optimistic Updates
Apply data changes instantly before the server responds, with automatic rollback on failure:
@boostsnippet("Optimistic Update with Router", "react")
import { router } from '@inertiajs/react'
function like(post) {
router.optimistic((props) => ({
post: {
...props.post,
likes: props.post.likes + 1,
},
})).post(`/posts/${post.id}/like`)
}
@endboostsnippet
Optimistic updates also work with `useForm` and the `
Dashboard
Active Users: {stats.activeUsers}
)
}
@endboostsnippet
@boostsnippet("Polling With Request Options and Manual Control", "react")
import { usePoll } from '@inertiajs/react'
export default function Dashboard({ stats }) {
const { start, stop } = usePoll(5000, {
only: ['stats'],
onStart() {
console.log('Polling request started')
},
onFinish() {
console.log('Polling request finished')
},
}, {
autoStart: false,
keepAlive: true,
})
return (