1 | initial version |
React's useContext can be used with Typescript's Record type in the following way:
type MyRecord<K extends string | number | symbol, V> = Record<K, V>;
interface MyContext {
data: MyRecord<string, string>;
}
const MyContext = createContext<MyContext>({
data: {}
});
const { data } = useContext(MyContext);
const value = data["key"]; // value has type string