From 618fb497c443662531eb3befe7696a04efe9651d Mon Sep 17 00:00:00 2001
From: Shin'ya Ueoka <ueokande@i-beam.org>
Date: Sun, 11 Apr 2021 18:00:51 +0900
Subject: Replace completion state with Custom Hooks

---
 src/console/completion/provider.tsx | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 src/console/completion/provider.tsx

(limited to 'src/console/completion/provider.tsx')

diff --git a/src/console/completion/provider.tsx b/src/console/completion/provider.tsx
new file mode 100644
index 0000000..c0de250
--- /dev/null
+++ b/src/console/completion/provider.tsx
@@ -0,0 +1,25 @@
+import reducer, { defaultState } from "./reducer";
+import React from "react";
+import { CompletionDispatchContext, CompletionStateContext } from "./context";
+
+interface Props {
+  initialInputValue: string;
+}
+
+export const CompletionProvider: React.FC<Props> = ({
+  initialInputValue,
+  children,
+}) => {
+  const initialState = {
+    ...defaultState,
+    completionSource: initialInputValue,
+  };
+  const [state, dispatch] = React.useReducer(reducer, initialState);
+  return (
+    <CompletionStateContext.Provider value={state}>
+      <CompletionDispatchContext.Provider value={dispatch}>
+        {children}
+      </CompletionDispatchContext.Provider>
+    </CompletionStateContext.Provider>
+  );
+};
-- 
cgit v1.2.3

