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

Expose useStore/useCommand hooks #104

Closed
emroot opened this issue Mar 23, 2023 · 1 comment
Closed

Expose useStore/useCommand hooks #104

emroot opened this issue Mar 23, 2023 · 1 comment

Comments

@emroot
Copy link

emroot commented Mar 23, 2023

hey I'm running into an issue where the search state value doesn't get cleared when I'm doing the following:

<Command.Input
  onKeyDown={e => {
    if (e.key === 'Enter' && e.currentTarget.value) {
      // Do some logic
     e.currentTarget.value = '';
    // state.search is still equal to the old value here
    }
  }}

It would be great to expose useStore so I can import and do

const store = useStore();
...
<Command.Input
  onKeyDown={e => {
    if (e.key === 'Enter' && e.currentTarget.value) {
      // Do some logic
     e.currentTarget.value = '';
    store.setState('search', '')
    }
  }}

PR for the change here: #105

@emroot emroot mentioned this issue Mar 23, 2023
@pacocoursey
Copy link
Owner

You should control the Command.Input component by passing value and onValueChange.

<Command.Input
  value={search}
  onValueChange={setSearch}
  onKeyDown={e => {
    if (e.key === 'Enter' && search) {
      setSearch('');
      // do whatever else you wanted
    }
  }
/>

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