eslint-plugin-react-perf icon indicating copy to clipboard operation
eslint-plugin-react-perf copied to clipboard

Support for non-JSX render functions

Open OliverJAsh opened this issue 7 years ago • 5 comments

Hi!

I just wondered if you had thought of also supporting non-JSX usages of React, where object/function identity is still a performance concern?

Thanks, Oliver

OliverJAsh avatar Dec 06 '17 10:12 OliverJAsh

We could also consider extending scope from objects/functions inside JSX to the whole render function, so this would error:

const MyComponent = () => {
  const toObject = { pathname: '/foo' };

  return <Link to={toObject}>foo</Link>;
};

OliverJAsh avatar Dec 06 '17 11:12 OliverJAsh

Yes! That was always part of the plan. Let me know if you are interested in contributing.

cvazac avatar Dec 08 '17 05:12 cvazac

@cvazac Is that yes to both ideas?

  1. Support non-JSX usages, e.g. React.createElement(MyComponent, { objectProp: {} })
  2. Support usages outside of virtual DOM but inside render functions

OliverJAsh avatar Dec 08 '17 09:12 OliverJAsh

I think both are important, but I'd prioritize 2 over 1. I had always planned to (attempt to) read more of the scope.

We report on:

  render() {
    return <Tag obj={{}} />
  }

But it's easily defeated with:

  render() {
    var o = {}
    return <Tag obj={o} />
  }

cvazac avatar Dec 08 '17 16:12 cvazac

@cvazac If it's OK with you, I'll open another issue to track 2, as I originally created this issue to track 1.

OliverJAsh avatar Dec 08 '17 16:12 OliverJAsh