use-dictionary
TypeScript icon, indicating that this package has built-in type declarations

0.1.0Β β€’Β PublicΒ β€’Β Published

MIT license Current npm package version Maintenance Downloads Total downloads Follow @jdnichollsc

useDictionary

A React useReducer() hook to use dictionaries (keys and values) πŸ”‘

Getting started

const App: React.FC = () => {

  const initialState = {
    id: '',
    name: '',
    password: '',
    termsAndConditions: false,
  };
  const {
    state,
    onUpdateValue, // Update a value from the dictionary
    onClearValue   // Remove a value from the dictionary
    onClear        // Remove all values from the dictionary
  } = useDictionary(initialState);

  const onSubmit = useCallback((event: React.FormEvent) => {
    event.preventDefault();
    console.log('Create User!', state);
  }, [state]);
  
  return (
    <form onSubmit={onSubmit}>
      <label>
        Document:
        <input
          type="text"
          value={state.id}
          onChange={(e) => onUpdateValue('id', e.target?.value)}
        />
      </label>
      <label>
        Name:
        <input
          type="text"
          value={state.name}
          onChange={(e) => onUpdateValue('name', e.target?.value)}
        />
      </label>
      <label>
        Password:
        <input
          type="password"
          value={state.password}
          onChange={(e) => onUpdateValue('password', e.target?.value)}
        />
      </label>
      <label>
        Accept terms and conditions:
        <input
          type="checkbox"
          checked={state.termsAndConditions}
          onChange={(e) => onUpdateValue('termsAndConditions', e.target?.checked)}
        />
      </label>
      <input type="submit" value="Submit" />
    </form>
  );
}

Contributing ✨

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated ❀️.
You can learn more about how you can contribute to this project in the contribution guide.

Supporting 🍻

I believe in Unicorns πŸ¦„ Support me, if you do too.

Donate Ethereum, ADA, BNB, SHIBA, USDT, DOGE:

Wallet address

Wallet address: 0x3F9fA8021B43ACe578C2352861Cf335449F33427

Please let us know your contributions! πŸ™

License βš–οΈ

This repository is available under the MIT License.

Happy coding πŸ’―

Made with ❀️

Package Sidebar

Install

npm i use-dictionary

Weekly Downloads

14

Version

0.1.0

License

MIT

Unpacked Size

11.7 kB

Total Files

9

Last publish

Collaborators

  • jdnichollsc