Я создаю новый контекст export const SchemaContext = React.createContext(null);
объект контекста создает в компоненте, который получает реквизит, который будет частью контекста.
type TSchemaProps<M = {}}> = {
model: M
};
export const Schema = <M,>({
model: globalModel
}: TSchemaProps<M>) => {
const [model] = useState<M>(globalModel);
const context = {
model,
isRoot: true
};
return (
<SchemaContext.Provider value={context}> // Type { model: M } is not assignable to null
{children}
</SchemaContext.Provider>
);
};
и теперь мы можем использоватьJSX универсальный для ввода
type TModel = {
docNum: number,
docDate: number,
group: {
kpp: string,
orgn: string
}
};
const MainComp = () => {
<Schema<TModel> />
}
Как я могу передать TModel в тип контекста?