react-tracking icon indicating copy to clipboard operation
react-tracking copied to clipboard

Multiple options.process behavior

Open oziniak opened this issue 7 years ago • 1 comments

Currently we encourage to use only one process on top level component, by making checks in constructor method of every tracking HoC

      constructor(props, context) {
        super(props, context);

        if (context.tracking && context.tracking.process && process) {
          console.error('[nyt-react-tracking] options.process should be used once on top level component');
        }
      }

Could these checks be performance consuming?

If there are several usages of options.process down a component tree desired behavior should be:

  • display error message (current behavior)
  • child's process should override parent's
  • merge return values of each
  • do nothing, because everyone should read documentation ;)
  • ...?

oziniak avatar Apr 07 '17 18:04 oziniak

One option is to guard these checks against a NODE_ENV check, which should be optimized and dead-code eliminated by a properly configured Webpack build:

      constructor(props, context) {
        super(props, context);

        if (process.env.NODE_ENV !== 'production' && context.tracking && context.tracking.process && process) {
          console.error('[nyt-react-tracking] options.process should be used once on top level component');
        }
      }

tizmagik avatar Apr 08 '17 03:04 tizmagik