palantir / tslint-react

:orange_book: Lint rules related to React & JSX for TSLint.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rule suggestion: consistent usage of <React.Fragment> vs <>

rherms opened this issue · comments

Would be nice to have a rule for preferring <React.Fragment> over <>. Would love to try tackling this myself if I have the time.

Hmm, what's the justification for this @rherms? Just to make things more readable?

Yeah readability and the fact that fragments are still relatively new so people might not know what <> means.

I dont have much of an opinion here. One other advantage of <React.Fragment> vs <> is that <> cannot have attributes so for keyed fragments you need to use <React.Fragment> (https://reactjs.org/blog/2017/11/28/react-v16.2.0-fragment-support.html#keyed-fragments)

Instead of preferring React.Fragment over <>, I think that it could be valuable to be enforce the usage of either one for consistency.

I agree that it would be better for the rule to enforce consistency similar to this eslint rule - https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-fragments.md

Closing due to deprecation timeline, see #210