confusingstraw opened a new issue #72:
URL: https://github.com/apache/incubator-flagon-useralejs/issues/72


   The `flagon-userale` NPM package has a handful of issues. The most egregious 
(in my eyes) is that, even if I don't explicitly start it, it will begin 
collecting/sending logs as soon as it is imported. Maybe there is some argument 
that this is intended behavior, but having it do this is probably a surprise 
for developers. For example, this code results in log collection/sending:
   
   ```jsx
   // in index.js
   import React from 'react';
   import ReactDOM from 'react-dom';
   import App from './App';
   
   ReactDOM.render(
     <React.StrictMode>
       <App />
     </React.StrictMode>,
     document.getElementById('root')
   );
   ```
   
   ```jsx
   // in App.jsx
   import { packageCustomLog } from "flagon-userale";
   import { useCallback, useEffect, useState } from "react";
   
   function App() {
     const [secondsElapsed, setElapsed] = useState(0);
     const resetTimer = useCallback(() => {
       setElapsed(0);
       packageCustomLog({ elapsed: secondsElapsed, logType: "timerReset" }, 
undefined, false);
     }, [secondsElapsed, setElapsed]);
   
     useEffect(() => {
       const timerId = setTimeout(() => {
         setElapsed(secondsElapsed + 1);
         packageCustomLog({ elapsed: secondsElapsed, logType: "timerUpdate" }, 
undefined, false);
       }, 1000);
   
       return () => {
         clearTimeout(timerId);
       };
     }, [secondsElapsed, setElapsed]);
   
     return (
       <main className="App">
         <p>App has been running for {secondsElapsed} seconds.</p>
         <button onClick={resetTimer}>Reset</button>
       </main>
     );
   }
   
   export default App;
   ```
   
   This surprises me, since it means that importing _any part of userale_ will 
automatically start the logging process. I'd imagine we ought to figure out a 
way to have it not start by default when imported via NPM. Of course, this is a 
breaking change.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to