react-amplitude-hooks
Advanced tools
Comparing version 0.9.0 to 0.9.1
@@ -13,16 +13,22 @@ "use strict"; | ||
exports.useAmplitudeContext = useAmplitudeContext; | ||
function AmplitudeProvider(props) { | ||
React.useEffect(function () { | ||
if (validation_1.isValidAmplitudeInstance(props.amplitudeInstance)) { | ||
if (props.apiKey) { | ||
props.amplitudeInstance.init(props.apiKey); | ||
function initAmplitude(apiKey, userId, amplitudeInstance) { | ||
return function () { | ||
if (validation_1.isValidAmplitudeInstance(amplitudeInstance)) { | ||
if (apiKey) { | ||
amplitudeInstance.init(apiKey); | ||
} | ||
if (props.userId) { | ||
props.amplitudeInstance.setUserId(props.userId); | ||
if (userId) { | ||
amplitudeInstance.setUserId(userId); | ||
} | ||
} | ||
else { | ||
console.error('AmplitudeProvider was not provided with a valid "amplitudeInstance" prop.'); | ||
} | ||
}, [props.apiKey, props.userId, props.amplitudeInstance]); | ||
}; | ||
} | ||
function AmplitudeProvider(props) { | ||
var apiKey = props.apiKey, userId = props.userId, amplitudeInstance = props.amplitudeInstance; | ||
var init = React.useMemo(function () { return initAmplitude(apiKey, userId, amplitudeInstance); }, [ | ||
apiKey, | ||
userId, | ||
amplitudeInstance | ||
]); | ||
init(); | ||
return (React.createElement(exports.AmplitudeContext.Provider, { value: { | ||
@@ -29,0 +35,0 @@ amplitudeInstance: props.amplitudeInstance, |
@@ -27,3 +27,3 @@ { | ||
"types": "dist/index.d.ts", | ||
"version": "0.9.0" | ||
"version": "0.9.1" | ||
} |
29340
291