import React , { useMemo , useState } from 'react' ; import { Engine } from 'tesfy' ; import TesfyContext from './TesfyContext' ; interface Props { engine : Engine ; children : React . ReactNode ; } export const createInstance = ( props ) => { return new Engine ( props ) ; } ; const TesfyProvider = ( { engine , children } ) => { const [ userId , setUserId ] = useState ( engine . getUserId ( ) ) ; const [ attributes , setAttributes ] = useState ( engine . getAttributes ( ) ) ; const value = useMemo ( ( ) => { const handleUserIdChange = ( userId ) => { engine . setUserId ( userId ) ; setUserId ( userId ) ; } ; const handleAttributesChange = ( attributes ) => { engine . setAttributes ( attributes ) ; setAttributes ( attributes ) ; } ; return { engine , userId , attributes , setUserId : handleUserIdChange , setAttributes : handleAttributesChange } ; } , [ engine , userId , attributes ] ) ; return < TesfyContext . Provider value = { value } > { children } < /TesfyContext.Provider>; } ; export default TesfyProvider ;