Please send suport for React Hooks, components class is obsolete.
Please support the function components with hooks.
Yes I would suggest a hooks implementation ASAP for react since that is the direction it's headed.
wrote a custom hook to replace withAITracking, seams to work ok, i have a 'key' paramter because i have a tabbed UI in the component i am tracking, and the key is the tab state
function useAITracking(componentName, key) {
useEffect( () => {
let start= new Date()
return () => {
reactPlugin.trackMetric({
average: (new Date() - start)/1000,
name: 'React Component (seconds)',
sampleCount: 1
}, { 'Component Name': componentName, 'Navigation': key });
};
}, [componentName, key])
}
I've done a write up on how you can create custom hooks to work with AppInsights, you'll find it here: https://dev.to/aaronpowell/combining-react-hooks-with-appinsights-5692
In it there is a Context, allowing you to useContext to access the React plugin, a hook for tracking a normal event (using trackEvent for AppInsights) and one for doing metric tracking like the HOC does.
Does it look like what people would expect from a programmatic model of AppInsights + Hooks?
Included in v 2.5.5 which is now fully deployed
@aaronpowell @MSNev is there any official documentation on how to use the new stuff for react hooks?
I second this question. Is there any documentation?
Docs have been written and are currently being reviewed by our content team. Fingers crossed they should be available soon.
Docs are now published - https://docs.microsoft.com/en-us/azure/azure-monitor/app/javascript-react-plugin#using-react-hooks
thanks for this!
@aaronpowell It would be great to have those docs in the react Readme.md as well
Good suggestion @dps88. I've opened a PR to add it.
Most helpful comment
Docs are now published - https://docs.microsoft.com/en-us/azure/azure-monitor/app/javascript-react-plugin#using-react-hooks