-
Notifications
You must be signed in to change notification settings - Fork 511
Description
Version:
@inertiajs/react
version: 2.0.11
Describe the problem:
When using router.reload() inside a useEffect() I get Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'component')
Steps to reproduce:
My particular use case is a page with 2 tabs. I only want to load the data for the tab 1 initially so the props for the second tab are set as optional on the controller with Inertia::optional(). The problem arises when the user is on tab 2 and reloads the page, the data is not returned because it's not a partial reload specific asking for the optional data. In order to solve this I set up a useEffect to make a partial visit
useEffect(() => {
router.reload({
data: { tab: 'payments' },
only: ['payments'],
preserveState: true,
preserveScroll: true,
replace: true,
});
}, []);
But this fails with Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'component')
If it is not a partial visit the error message is other Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'version')
Is there a better way to achieve my expected result? I dont use defer because the second tab data is heavy and dont want to fetch it unless the user explicitly access it