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

Resetting input field #5

Open
oyeanuj opened this issue Sep 11, 2020 · 1 comment
Open

Resetting input field #5

oyeanuj opened this issue Sep 11, 2020 · 1 comment

Comments

@oyeanuj
Copy link

oyeanuj commented Sep 11, 2020

Hey @alex-cory, thanks for creating this excellent library! One small issue while using this library: there doesn't seem to be an easy way to reset the state or the input, since the only way for change is an onChange that requires an event passed in.

Any ideas on how that might be achieved?

@iamthesiz
Copy link
Collaborator

try this and let me know if it works.

const App = () => {
  const { email, bind } = useEmailAutocomplete()
  const rerender = useReducer(() => ({}), [])[1]
  
  const onSubmit = () => {
    // your logic
    email.address = '' // will reset it, but will not trigger a rerender
	// depending if you are updating state after this for anything,
	// you might not need this rerender(). I know it's a little hacky, but it should work
    rerender()
  }
  
  return <input {...bind} />
}

I don't think it would be too difficult to add a function like. I just think it might confuse people if it's not well documented.

const App = () => {
  const { email, setEmail, bind } = useEmailAutocomplete()

  const onSubmit = () => {
    // your logic
    setEmail('') // this does not exist
  }
  
  return <input {...bind} />
}

Do you have any suggestions for syntax?

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