Comments (8)
@adidahiya i'm curious how you handle simple conditional templates without multiline jsx?
for example:
{
variableThatCouldBeUndefined &&
<div>
<span>
{variableThatCouldBeUndefined}
</span>
</div>
}
I started trying to refactor these kinds of things into functions, but i found that for simple cases like this it actually made the code much less readable as it scattered the pieces all over the file. I'm curious how you handle these and similar cases with this rule on.
from tslint-react.
@scamden yeah, I'd say that's fair criticism for this rule and might warrant a new rule option to allow simple conditional templates (limit the conditional expression itself to one line, otherwise this is easily abused).
currently, I end up with a lot of code like this:
render() {
return (
<div>
{this.maybeRenderA()}
{this.maybeRenderB()}
</div>
);
}
private maybeRenderA() {
if (foo) {
return ...
}
}
private maybeRenderB() {
if (bar) {
return ...
}
}
... I personally don't mind it too much but it is a stylistic preference that not everyone's going to agree with.
I mostly didn't like seeing a lot of JSX code like this:
{this.props.items.map((i: Item) => (
<ItemComponent ... />
))}
from tslint-react.
I just disabled it :)
{
"extends": ["tslint:recommended" ,"tslint-react"],
"rules": {
"jsx-no-multiline-js": false
}
}
from tslint-react.
What is your alternative to this? Is there a better way that I am unaware of?
{this.props.items.map((i: Item) => ( <ItemComponent ... /> ))}
Yes, disable the rule and be happy
from tslint-react.
What is your alternative to this? Is there a better way that I am unaware of?
{this.props.items.map((i: Item) => (
<ItemComponent ... />
))}
from tslint-react.
ya that could be cool to limit the scope of it slightly. i also had some terrible nested conditionals that were all scoped to one expression at the top level so i can see the desire to prevent that. but ya seems like a middle ground would be helpful
from tslint-react.
saying maybeA and maybeB is very different from saying if A else B
maybeA and maybeB means both can render at the same time.
from tslint-react.
This rule is most for readability than another one reason and its awesome, I just get a legacy project with nested multiline jsx which takes the code readability to trash. I just want to say that since most people criticized that rule and IMO this rule is awesome.
from tslint-react.
Related Issues (20)
- React must be in scope in tsx file HOT 4
- Feature request: pair ReactDOM.unmountComponentAtNode with ReactDOM.render calls. HOT 1
- Why jsx-alignment do not includes automatic code fix? HOT 1
- Rule suggestion: no unneeded <React.Fragment> or <> HOT 1
- jsx-wrap-multiline does not enforce end-paren if begin-paren is valid HOT 1
- jsx-no-bind bug? HOT 5
- Pull in rules from tslint-microsoft-contrib HOT 3
- Cannot set "jsx-boolean-value" to 'never' ? HOT 1
- jsx-wrap-multiline does not check nested JSX HOT 2
- New rule suggestion: jsx-singleline-no-parens HOT 1
- jsx-no-multiline-js: allow multiline block comments HOT 2
- Migrate to eslint-plugin-react HOT 2
- react-ssr-friendly HOT 3
- Roadmap: tslint-react -> eslint-plugin-react HOT 1
- jsx-self-close rule doesn't actually support autofix HOT 1
- jsx-wrap-multiline issue with trailing-comma HOT 2
- Automatically ignore null keyword usage within getDerivedStateFromProps method HOT 3
- Allow/disallow curly braces for string literal attributes (enforce double/single quotes only) HOT 1
- Missing LICENSE file in npm package HOT 1
- jsx-curly-spacing accepted formats HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tslint-react.