blob: c0de250b2c6e783010f836499cc819eeff38deac (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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>
);
};
|