AlexGilleran/jsx-control-statements

In For Statement with 'index' key but no 'each', the 'index' is pouplated with values not indexes

NikolayPeev opened this issue · 5 comments

I mean when I try this:

        <For index="index" of={[100, 200, 300]}>
          <span key={index}>{index}</span>
        </For>

I get 100, 200, 300 and I'd like to get 1, 2, 3.
As far as I saw, when 'each' is missing the index key is passed as first param, so it takes the place of 'each'.
Is this a known issue?

Huh. No not a known issue - I suppose it makes sense that it'd do that because if you don't specify an each attribute, index is the first parameter that gets added to the list of parameters for the map method. Thanks for reporting it!

So, is it a bug then?
I could add a simple check, and if there is no 'each', it could add a placeholder.

Yeah definitely a bug - the fix should be as simple as removing that assumption from the code, it shouldn't even need a specific check.

Sorry to leave this sitting, been trying to get a Random Hacks of Kindness project done and move house :(

Fixed on current master, but not released yet.

Fixed in v3.1.3! 👌