Comments (8)
When you delete items by removing then from SortableGrid's children, make sure you're not assigning them their key-value from map-function index, because it causes the last item to disappear instead of the intended one.
This happens because SortableGrid keeps copies of the children, and removes them based on missing keys when props update. If you assign the index of a map-function as a key for a child, SortableGrid only sees that the last key (last index) is missing and removes that.
from react-native-sortable-grid.
First we setup our state data:
constructor() {
super()
this.state = {
favorites_data:
[{... Your JSON ...}]
};
...
Then added a function to add children:
addChildItem(itemData){
this.setState({
favorites_data: this.state.favorites_data.concat(itemData)
});
}
And in our render function we loop through the state:
renderChildren(){
return this.state.favorites_data.map( (item, index) =>
<View
...
Also if you are aiming for performance it is good to restrict the updates:
shouldComponentUpdate(nextProps, nextState){
if (this.state.favorites_data !== nextState.favorites_data) {
return true;
}
return false;
}
For removing (seems to only remove last item... looking into this)
removeChildItemAt(index){
var tmpArray = this.state.favorites_data.slice()
tmpArray.splice(index, 1);
this.setState({ favorites_data: tmpArray })
}
from react-native-sortable-grid.
@ollija Thank you, that is issue I was experiencing (removing only last item), however when I took off the key value when I map, only one single icon renders, instead of the 10 that should render.
from react-native-sortable-grid.
Well, you need to assign them some key. Maybe increment a number each for each item and use that as a key?
from react-native-sortable-grid.
Hrmm not sure I fully understand, Do you mean that the internal index and external should have different IDs? And thus you target this ID instead of the internal index?
I am still trying to figure out best way to implement the removal and insertion (Adding to end works fine) of items.
from react-native-sortable-grid.
hello guys, i fixed it by generating random keys numbers,
key={Math.random() * 1000}
this delete the particular item not the last one.
from react-native-sortable-grid.
@indivisable have you solved this problem? I'm facing the same issue...
from react-native-sortable-grid.
so finally I got it working as well in updating adding children, key={Math.random() * index}. In my opinion I guess they need to add this on the documentation.
from react-native-sortable-grid.
Related Issues (20)
- Drag and Drop fails and the Grid collapses. HOT 3
- Drag icons in a long ScrollView with autoscroll HOT 2
- Still supported? HOT 3
- onDragStart not working with delete functionality?
- How to make draggable item clickable?
- want some inactive items not to be sorted, inactive property is not working HOT 5
- Can i Add outside item to items inside grid? HOT 1
- Android performance is sluggish and unusable HOT 1
- different quantities of items in different rows HOT 9
- how to slide item to left or right and delete
- Is there an example where item values change on reorder? HOT 1
- Add an item HOT 1
- inactive props doesn't work for me HOT 3
- how to set inactive = false. to it's child HOT 5
- Deprecated Lifecycle Method .....Warning: componentWillReceiveProps has been renamed... HOT 1
- scroll grid not work
- When will the latest commit be merged into master?
- restrict to one movement
- Not working with TouchableOpacity/Pressable
- Customize number of items in each column/row
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 react-native-sortable-grid.