import React, { createContext, memo, useState, } from '../../lib/teact/teact'; import useContext from '../../hooks/data/useContext'; const TestingContext = createContext('default value'); const ContextConsumer = ({ children, debugKey }: { children?: any; debugKey?: string }) => { const value = useContext(TestingContext); if (debugKey) { // eslint-disable-next-line no-console console.log(`ContextConsumer ${debugKey}`, value); } return (
{`Current context value: ${value}`} {children}
); }; const MemoizedWrapper = memo(({ children } : { children: any }) => { return
{children}
; }); const ContextSwapper = ({ value, children } : { value: string; children: any }) => { return (
Swapped {value} {children}
); }; const TestContext = () => { const [value, setValue] = useState(Math.random().toString()); const [isSwapping, setIsSwapping] = useState(false); const Wrapper = isSwapping ? ContextSwapper : TestingContext.Provider; return (
<>
{!isSwapping &&
Fast list item
}
); }; export default TestContext;