The project isn't a React WebSite, it's a mobile app written in React Native and i'm using Redux Toolkit.
I've a React component with a Redux store (it's user), and a function (onSwipe) that i pass to an onSwipe event used by a component of a library.
In the useEffect (it's just a debug code) my store is updating every time i call the dispatch in the onSwipe function, but in the function my store is not updating... The data remain the same as the first rendering.
They must update in both, because i need it to create the new Array that i've to send to DB.
Component.tsx
const user = useSelector((state: RootState) => state.user);const dispatch = useDispatch(); useEffect(() => { console.log("Effect", user.likes);}, [user]);const onSwipe = useCallback((direction: string, uid: string) => { if (direction === "right") { console.log("Like", user.likes); const newLike = [...user.likes, uid]; void saveLikeFirebase(user.uid ?? "", newLike).then(() => { dispatch(changeLike(uid)); }) } else { void saveDislikeFirebase(user, user.dislikes, uid).then(() => { dispatch(changeDislike(uid)); }) }}, [user, user.likes])
reducer.ts
changeLike: (state, action) => { const likes: string[] = [...state.likes, action.payload]; return { ...state, likes };},
I've tried a lot of things. I've tried to force rendering using an useState instead of Redux store, intializing it with my first Rendering store, but nothing changed.
I've try to remove useCallback to force the function update every time, but nothing.
I've try to reset all the cache of the project and rebuild it.
IDK what other i can do