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

export StateUpdater and other utility types #222

Open
bennypowers opened this issue Jan 17, 2021 · 0 comments
Open

export StateUpdater and other utility types #222

bennypowers opened this issue Jan 17, 2021 · 0 comments

Comments

@bennypowers
Copy link
Collaborator

consider:

const setWith = (setter: StateUpdater<string>) =>
  ({ target: { value } }) =>
    setter(value);

function AddUser(this: ApolloMutationElement) {
  const [mutate, { data, error, loading }] = useMutation(AddUserMutation);

  const [name, setName] = useState('');
  const [twitter, setTwitter] = useState('');

  return html`
    <mwc-textfield label="Name" value="${name}" @input="${setWith(setName)}"></mwc-textfield>
    <mwc-textfield label="Twitter handle" value="${twitter}" @input="${setWith(setTwitter)}"></mwc-textfield>
  `;
}

customElements.define('add-user', component(AddUser));

In cases like these it would be nice to just

import type { StateUpdater } from 'haunted';
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

1 participant