-
I want to perform an asynchronous action inside a command, but I can't figure out how to close the pallet once the action is complete. export function AppCommandPalette () {
const commands = [
{
name: 'Do Something',
command() {
doSomething().then(() => {
doSomethingToCloseTheModalHere();
});
},
},
];
return (
<CommandPalette commands={commands} resetInputOnOpen={true} />
);
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Begin by setting Now that the palette won't close when the user selects the async command use a react hook to update
Here's a complete example: |
Beta Was this translation helpful? Give feedback.
Begin by setting
closeOnSelect
tofalse
which will prevent the palette from automaticaly closing. Also you can optionaly setshowSpinnerOnSelect
tofalse
to prevent the spinner from showing. MakeresetInputOnOpen
true so that the palette will reset the next time its opened.Now that the palette won't close when the user selects the async command use a react hook to update
open
prop tofalse
. For the next time the palette is opened you may need to change the open state back totrue
againHere's a complete example:
https://codesandbox.io/s/react-command-palette-closemodal-hoq90?file=/src/index.js