I am using useEffect to save all the data coming from redux in a state.
Below is my code:
const [items, setItems] = useState();
React.useEffect(() => {
setItems(createMenuReducer.data.product);
console.log("item", items);
}, [items]);
<ScrollView>
{createMenuReducer &&
items?.map((item, index) => {
return (
<ItemComponent
item={item}
/>
);
})}
</ScrollView>
console.log output:
item undefined
but when I click save again then all the items are getting consoled:
item (10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
I tried to update state, thinking it will also update the UI, but that is not happening. I am getting a blank page when loads first time, but when I click save again, all the items are shown in UI. How to fix this so that all the items are on the screen when the app loads??