Eslint-plugin-react: react-in-jsx-scope does not understand fragments

Created on 4 Apr 2018  路  3Comments  路  Source: yannickcr/eslint-plugin-react

If you use <></> fragment syntax the react-in-jsx-scope rule will not declare React as in scope and the no-unused-vars will fail on the React import.

However React is required for fragment syntax as well as normal element syntax.

import React from 'react';

export default () => <>fragment</>;
enhancement help wanted react 16

All 3 comments

The fix for this appears to be extremely simple. react-in-jsx-scope.js just needs to apply itself to JSXOpeningFragment in addition to JSXOpeningElement.

@dantman that sounds great! However, we'll also want to make sure this change only applies after whichever React version added fragment support.

seems like 16.2.0 -version introduced improved support for fragments.
https://reactjs.org/blog/2017/11/28/react-v16.2.0-fragment-support.html

Was this page helpful?
0 / 5 - 0 ratings