Comments (10)
Good idea. It could be compiled to something like this:
Object.keys(obj).map(function(value, index) {
//...
});
to make it work properly in context of React. Each item would have to be called as obj[value]
though, which is a bit ugly, but I can't come up with a better solution
from jsx-control-statements.
What's the advantage over just writing <For each="key" of={Object.keys(obj)}>
?
Doing this would mean we'd have to put code into every for loop that checks whether it's an object or an array, so I'm pretty reticent to do it unless there's a more pressing reason than saving a few keystrokes.
from jsx-control-statements.
@AlexGilleran Agree. <For each="key" of={Object.keys(obj)}>
seems sufficient.
from jsx-control-statements.
Would <For k="key" v="val" over="obj" >
(ie; using different props) make the implementation any simpler?
from jsx-control-statements.
Personally I would rather keep the For tag API simple and easy to understand, and let people just call Object.keys()
, rather than introduce new syntax/props for iterating over objects instead of sets. Otherwise, what should the tag do if you specify k
/v
while iterating over a list? Throw? Both contain the same value? eeh, I really don't see any downside to people just using Object.keys
. But I do see downside to having people learn new syntax that they don't already know to use the component properly (increased learning curve).
from jsx-control-statements.
Otherwise, what should the tag do if you specify k/v while iterating over a list? Throw?
Yes, it should throw.
It's just annoying to have to both do Object.keys
and obj[key]
. But I'm coming from a CoffeeScript background, where easy object looping is a thing; now that I'm in ES6 (as are many others), I have to get used to Object.keys
anyway.
I think this is fine as-is. But it might be worth adding an example to the docs.
from jsx-control-statements.
+1 for an example of using Object.keys
in the docs, since it's not necessarily super obvious and would be a good thing to demo.
from jsx-control-statements.
Yeah that makes sense, I will get on that.
from jsx-control-statements.
Documentation updated in 1.1.1
from jsx-control-statements.
Sweet!
from jsx-control-statements.
Related Issues (20)
- The control statements don't narrow TypeScript types HOT 1
- TypeScript type for children is missing a render function HOT 1
- TChildren conflicts with ReactNode children HOT 2
- Why do we need ```transform-react-inline-elements``` plugin ?
- Switch-case style control statement HOT 2
- Problem with ./node_modules/tsx-control-statements/components.ts HOT 3
- Typo error HOT 1
- Support babel macros HOT 2
- conditional statements don't work unless wrapped in brackets. is this supposed to happen? HOT 1
- Not working with laravel-mix with webpack config
- Support babel-plugin-macros HOT 7
- Outdated npm link in description on GitHub project HOT 2
- Uncaught ReferenceError: For is not defined HOT 5
- Not working with create-react-app HOT 7
- If is not defined HOT 4
- App breaks if i try to directly access the url - With Error - Choose is not defined HOT 1
- React-Native:Installation-Guide HOT 2
- last published version is 3 years old HOT 2
- ESLint autofix HOT 2
- Undefined is not a function with new JSX transform with react 17 HOT 3
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 jsx-control-statements.