import React, { createContext, useContext, useState, useEffect } from 'react'; interface SocialEmbedsContextType { isSocialEmbedAllowed: Record; setIsSocialEmbedAllowed: React.Dispatch< React.SetStateAction> >; isAllowedOnce: Record; setIsAllowedOnce: React.Dispatch< React.SetStateAction> >; } const SocialEmbedsContext = createContext( undefined ); export const SocialEmbedsProvider: React.FC = ({ children }) => { const [isSocialEmbedAllowed, setIsSocialEmbedAllowed] = useState< Record >({ instagram: false, twitter: false, tiktok: false, youtube: false, facebook: false }); const [isAllowedOnce, setIsAllowedOnce] = useState>({ instagram: false, twitter: false, tiktok: false, youtube: false, facebook: false }); useEffect( () => { // Set defaults or perform any logic needed to initialize the values setIsAllowedOnce({ instagram: isSocialEmbedAllowed.instagram, twitter: isSocialEmbedAllowed.twitter, tiktok: isSocialEmbedAllowed.tiktok, youtube: isSocialEmbedAllowed.youtube, facebook: isSocialEmbedAllowed.facebook }); }, [isSocialEmbedAllowed] ); return ( {children} ); }; export const useSocialEmbedsContext = () => { const context = useContext(SocialEmbedsContext); if (!context) { throw new Error( 'useSocialEmbedsContext must be used within a SocialEmbedsProvider' ); } return context; };