Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

339
Views
Could not remove item in firebase when delete using redux toolkit action

I'm making a note app, now i'm okey with fetch data and add data but when i try to remove data, it work so weird, if i have 5 item, after first time remove, it will not apply, after remove the next item, it will remove the previous, example i have 5 item, then i press delete one item,it did'nt remove anything, but if i press delete another item, it remove the last one, i don't know why it not work, here is the code

Here is the redux reducer code:

    const noteReducer = createSlice({
      name: "note",
      initialState: NoteList,
      reducers: {
        removeNote: (state, action: PayloadAction<NoteI>) => {
          return state.filter((item) => item.id !== action.payload.id);
        }
      }
    });

Here the note structure on firestore will be like this, it contain

{
  userName:"blabla"
  email:"blabla@gmail.com"
  note:[]  <== an array of object note
}

Here is the function i use to delete note:

    export default function NoteList(props: noteListI) {
      const { title, note, id, date } = props;
      const dispatch = useDispatch();
      const userInfo: user = useSelector(
        (state: RootState) => state.persistedReducer.firebase.userInfomation
      );
      const data = useSelector((state: RootState) => state.persistedReducer.note);
    
      const updateDeletedNoteFirebase = async () => { // deleteFuntion
        await firestore()
          .collection("Users")
          .doc(userInfo.email)
          .update({
            note: data
          })
          .then(() => {
            console.log("delete success");
          });
      };
      const removeSelectedNote = () => {. //delete LocalItem
        dispatch(removeNote({ id: id }));
      };
      return (
        <View>
          <TouchableOpacity
            onLongPress={() => {
              removeSelectedNote();
              updateDeletedNoteFirebase();
              console.log("data",data); //console the same 
            }}
          >
            <Note />
          </TouchableOpacity>
        </View>
      );
    }

But problem is when i log the data it remain the same

Here is the gif to show what going on here

It still work but i don't know why it only work when i press delete again, if refesh it will remain the same, but if i delete twice, refresh it will delete the previous, not two item

Please help, thank you a lots

Note that i remove all unrelated code and keep the relate one

enter image description here

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!