Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow WhenVisible Component to Accept params Alongside data for Enhanced Customization #2065

Closed
wants to merge 2 commits into from

Conversation

HichemTab-tech
Copy link

This PR updates the getReloadParams function to allow users to pass both data and custom params when using the WhenVisible component in Inertia v2.

Old Behavior:
Previously, if the data prop was provided, the params prop was ignored. This restricted the user's ability to pass additional parameters when reloading the component, leading to a lack of flexibility.

New Behavior:
Now, the params prop can be used in combination with the data prop. This allows users to extend the request parameters beyond the basic data specification.

  • Updated code snippet:
    const getReloadParams = (): Partial<ReloadOptions> => {
        if (data) {
            return {
                only: (Array.isArray(data) ? data : [data]) as string[],
                ...params
            }
        }
    
        if (!params) {
            throw new Error('You must provide either a `data` or `params` prop.')
        }
    
        return params
    }

Use Case:
Consider the following example:

<WhenVisible
    always
    fallback={(
        <SpinnerWithRetry/>
    )}
    data='rooms'
    params={{
        data: {
            lastRoomId: rooms.data[rooms.data.length - 1].id
        },
        onBefore: async (data) => {
            console.log("onBefore", data);
        }
    }}
    children={null}
/>

With this change, both data and params are processed, ensuring that custom params.data like lastRoomId are passed correctly, enabling more flexible and complex reload scenarios.

BTW this can resolve my issue here : #2064

Thanks.

Previously, the WhenVisible component was not considering additional data properties passed through params. This change ensures that any extra data provided via params is merged correctly, enhancing the component's flexibility and usability.
@HichemTab-tech HichemTab-tech closed this by deleting the head repository Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant