I am not sure if this is possible or going against the grain, but I am trying to derive the type from a contextAPI object in a consumer component.
The code below represents my component getting data from a React context hook. I want to mark nameKey in the TS interface as type keyof Data. Is this possible? If so, how would I do it?
import React, { FC } from ‘react’; import { useFormContext } from ‘../useFormContext’ interface FormTextFieldProps{ nameKey: // this should be the type: keyof Data, data being the data from the useFormcontext } export const FormTextField: FC<FormTextFieldProps> = ({ nameKey, }) => { const { data } = useFormContext() return ( <input type=”text” name={data[nameKey]} > ); };
submitted by /u/cantThinkOfGoodNameR
[link] [comments]