If I call my reload
method for the first time via useEffect
it contains my data, but if I called via onRefresh
at runtime, it gives me empty data.
Why? How should I save that? Is it a problem on which thread onRefresh
is called?
For more information about my item please look to this question, maybe it is the same issue.
const MyScreen = ({ items }) => {
const [initialItems, setInitialItems] = useState(items)
useEffect(() => {
reload()
}, [])
const reload = () => {
console.log(initialItems) // same value
console.log(items) // same value
}
return (
<FlatList
...
refreshControl={
<RefreshControl
refreshing={isRefreshing}
onRefresh={() => reload()}
/>
}
...
/>
)
}
const mapStateToProps = (state) => {
return {
items: state.items, // I tried this also with [...state.items]
}
}
My mistake was copying my Array like that: xArray = yArra
it means call by reference and not by value.