-
|
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
closeOnSelecttofalsewhich will prevent the palette from automaticaly closing. Also you can optionaly setshowSpinnerOnSelecttofalseto prevent the spinner from showing. MakeresetInputOnOpentrue 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
openprop tofalse. For the next time the palette is opened you may need to change the open state back totrueagainHere's a complete example:
https://codesandbox.io/s/react-command-palette-closemodal-hoq90?file=/src/index.js