'Usestate is not updating data to display
So on my project i have a firebase.firestore which my flow is that first it needs to fetch the data without any filter so i use the UseEffect hook
so this code is the first
useEffect(()=>{
getVidWrapepr(options)
store.subscribe(update)//trigger when a dispatch
},[])
and it goes to the function getVidWrapper
const getVidWrapepr = (options) => {
console.log("second render");
getVideos(options).then((data)=>{
console.log("inside get videos", data);
var redData = {
reducerName:"videos",
data:data
}
SetLoading(false)
store.dispatch(middlewareDispatch(redData)) //trigger the store.subscribe
}).catch(
(errr)=>{
console.log("error",errr);
}
)
}
after that because a dispatch has been excute it will trigger the store.subscribe(update)
which will assign the data to vids to display
function update(){ // final destination
SetVids(store.getState().reducer.videos)
SetLoading(false)
}
on the first time it renders it work but i have a button that will apply filters after i click this button it should apply the filter and the number of data will be deducted
const applyFilter = (options) =>{
SetOptions(options)
}
the option are the function
but after that nothing changes on the data. i dont know whats wrong about this
note: iam new to react-native
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
