import React, { createContext, ReactNode, useContext, useState } from 'react'; const MyContext = createContext(undefined); export const MyProvider: React.FC<{ children: ReactNode }> = ({ children }) => { const [my_context, setMyContext] = useState('initial value'); const [test_first, setTestFirst] = useState(undefined); const [test_second, setTestSecond] = useState(undefined); const [test_third, setTestThird] = useState(undefined); return ( {children} ); }; export const useMyContext = (): MyContextProps => { const context = useContext(MyContext); if (!context) { throw new Error('useMyContext must be used within a MyProvider'); } return context; }; interface MyContextProps { my_context: string; setMyContext: React.Dispatch>; // test_first: IFirst | undefined; setTestFirst: React.Dispatch>; test_second: ISecond | undefined; setTestSecond: React.Dispatch>; test_third: IThird | undefined; setTestThird: React.Dispatch>; } interface IFirst { test_s: string; test_i: number; } interface ISecond { test_s: string; test_i: number; content: IFirst[] | []; } interface IThird { test_s: string; test_i: number; content: ISecond[] | []; }