Skip to content

Instantly share code, notes, and snippets.

@dance2die
Created March 30, 2019 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dance2die/043283084a0ae76b7a8bef2c86799fb6 to your computer and use it in GitHub Desktop.
Save dance2die/043283084a0ae76b7a8bef2c86799fb6 to your computer and use it in GitHub Desktop.
function useTrie(
initialWords: Word[],
isCaseInsensitive = true,
getText: TextSelector = obj => obj
): ITrie {
const trie = new Trie(initialWords, isCaseInsensitive, getText);
const [state, dispatch] = React.useReducer(reducer, { trie, word: '' });
// add/remove removed for brivity
return { ...state.trie, add, remove };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment