11import { RudderAnalytics } from '@rudderstack/analytics-js'
22import type { LoadOptions } from '@rudderstack/analytics-js'
3- import { createContext , useContext , useEffect , useMemo , useState } from 'react'
3+ import { createContext , useContext , useMemo , useState } from 'react'
44import type { ReactNode } from 'react'
55import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect'
66import { destSDKBaseURL , pluginsSDKBaseURL } from '../constants'
@@ -79,7 +79,6 @@ export function AnalyticsProvider<T extends Events>({
7979 settings,
8080 loadOptions,
8181 shouldRenderOnlyWhenReady = false ,
82- shouldLoadAnalytics = false ,
8382 onError,
8483 onEventError,
8584 allowedConsents,
@@ -91,13 +90,7 @@ export function AnalyticsProvider<T extends Events>({
9190 undefined ,
9291 )
9392
94- const shouldLoad = useMemo ( ( ) => {
95- if ( shouldLoadAnalytics ) {
96- return ! ! settings ?. writeKey
97- }
98-
99- return false
100- } , [ shouldLoadAnalytics , settings ?. writeKey ] )
93+ const shouldLoad = useMemo ( ( ) => ! ! settings ?. writeKey , [ settings ?. writeKey ] )
10194
10295 useDeepCompareEffectNoCheck ( ( ) => {
10396 if ( shouldLoad && settings ) {
@@ -129,22 +122,11 @@ export function AnalyticsProvider<T extends Events>({
129122 setAnalytics ( { ...analytics , trackLink : trackLink ( analytics ) } )
130123 setIsAnalyticsReady ( true )
131124 } )
132- } else if ( shouldLoadAnalytics && ! shouldLoad ) {
125+ } else if ( ! shouldLoad ) {
133126 // When user has refused tracking, set ready anyway
134127 setIsAnalyticsReady ( true )
135128 }
136- } , [ onError , settings , loadOptions , shouldLoad , shouldLoadAnalytics ] )
137-
138- useEffect ( ( ) => {
139- if ( isAnalyticsReady ) {
140- internalAnalytics ?. consent ( {
141- consentManagement : {
142- allowedConsentIds : allowedConsents ,
143- deniedConsentIds : deniedConsents ,
144- } ,
145- } )
146- }
147- } , [ internalAnalytics , isAnalyticsReady , allowedConsents , deniedConsents ] )
129+ } , [ onError , settings , loadOptions , shouldLoad ] )
148130
149131 const value = useMemo < AnalyticsContextInterface < T > > ( ( ) => {
150132 const curiedEvents = Object . entries ( events ) . reduce (
0 commit comments