Skip to content

feat: react, update useIonModal signature to accept all parameters in one object #27548

Description

@eric-horodyski

Prerequisites

Describe the Feature Request

Currently, the useIonModal hook has this signature:

const [present, dismiss] = useIonModal(component: ReactComponentOrElement, componentProps?: any);

A common React paradigm is to enclose all input parameters into one object. This is primarily done to destructure the bits of input/output that you need at any moment in time:

const { getAccount } = useAccountsAPI();

const MyComponent = ({ myProp1, myProp2 }) => <div>{myProp1}</div>;

Describe the Use Case

It's also become a pattern developers use as context clues to figure out what something does.

This can make the current useIonModal() signature confusing:

const [present, dismiss] = useIonModal(MyComponent, { myProp1, myProp2, onDismiss: dismiss() });

Describe Preferred Solution

Adjusting the signature could improve the ergonomics of the hook:

const [present, dismiss] = useIonModal({ component: ReactComponentOrElement, props?: any);

Taken further, we can use TypeScript's generics to type the component's props:

const [present, dismiss] = useIonModal<T>({ component: ReactComponentOrElement, props: T});

Describe Alternatives

No response

Related Code

No response

Additional Information

No response

Activity

  1. changed the title [-]feat: revise useIonModal signature[/-] [+]feat: react, update useIonModal signature to accept all parameters in one object[/+] on Jun 8, 2023
  2. added
    type: feature request
    package: react
    on Jun 8, 2023
  3. seikosantana commented on Jul 5, 2023

    @seikosantana

    I like the useIonModal<T>. Was about to propose that before i found this issue 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: reacttype: feature request

    Fields

    Stage

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions