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

Hooks can't be used in a modal? #5

Open
kotx opened this issue Mar 16, 2022 · 3 comments
Open

Hooks can't be used in a modal? #5

kotx opened this issue Mar 16, 2022 · 3 comments

Comments

@kotx
Copy link

kotx commented Mar 16, 2022

For example, anything that uses useCustomId like useSelect can't be used in a useModal context. Is this intentional (e.x. a constraint of the Discord API) or an oversight?

@kotx kotx changed the title Hooks that require to be used in a command can't be used in a modal? Hooks can't be used in a modal? Mar 16, 2022
@kotx
Copy link
Author

kotx commented Mar 22, 2022

@mrbbot I still can't get this to work, any tips?

@mrbbot
Copy link
Owner

mrbbot commented Mar 22, 2022

Hey! 👋 Apologies for the delayed reply. Yes, this is intentional. All custom IDs need to be declared at the top level so they're the same across calls. Don't worry if you only use them in your useModal callback, they'll just get ignored if you don't use them all the time.

export function cmd() {
  const selectId = useSelectMenu(...);
  const modalId = useModal(() => {
    return (
      <Message>
        <Select id={selectId}>...</Select>
      </Message>
    );
  });

  // Ok to ignore selectId here
  return <Modal id={modalId}>...</Modal>;
}

@kotx
Copy link
Author

kotx commented Mar 23, 2022

That makes sense, thanks! Works now.

Also it turns out I can't put a Select in an Embed, so it was outputting [object Object] in the Embed instead of the actual Select element. Might be worthwhile to add a check for this if possible?

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

No branches or pull requests

2 participants