I am using Redux in my React-Native app to manage an array of items. I get the oddest behavior however.
Project can be found here (https://github.com/jhessin/BigButtonLists)
Relevant files are:
redux/reducers/ListsReducer.js
redux/actions.js
screens/lists/SortAllListsScreen.js
and maybe redux/types.js - but that is pretty standard
I have created two actions to move an item up or down in the list by swapping it with it's neighbor. (redux/reducers/ListsReducer.js) I am not modifying state directly, but am instead using a copy (newState).
The strangeness is that when using the up button the app behaves as expected, however when using the down button the array is completely corrupted and filled with null values no matter where I use it.
I have even tried to trick it into thinking I pushed the up button on the next item in both the action and by calling the up function on index + 1 in the parent component, but I get the same result. Please help?
EDIT: I figured it out. It turns out that for some reason I was getting the index in the form of a string. When I subtracted 1 from it it was automatically converted to a number, but when adding a 1 it simply concatenated it - so 1 would be swapped with 11 etc. I simply converted it to a number and it works now. This issue seems to be caused by the List component that I use from the native-base library and not redux (just couldn't figure it out so I wasn't sure who to ask).