2 years ago

#59941

test-img

Ceren Keklik

CHROME-EXTENSION: state inside of the same state

I am working on a project that creates a chrome extension. I use slices with redux-toolkit. Here is my first version of redux:

 case 'TABMANAGER_UPDATE':
      let newUrl =
        action.payload && action.payload.url && new URL(action.payload.url)
      return {
        ...state,
        tabManager: {
          ...state.tabManager,
          [action.payload.tabId]: newUrl.origin,
        },
      }

I am trying to rewrite for toolkit. However, my state adds same state inside of that? How can I fix this? Here is the photo that shows my problem: enter image description here

Here is my just one slice:

import { createSlice } from '@reduxjs/toolkit'

export const tabManagerReducerSlice = createSlice({
  name: 'tabManager',
  initialState: {
    tabManager: {},
  },
  reducers: {
    tabManagerUpdate: (state, action) => {
      let newUrl =
        action.payload && action.payload.url && new URL(action.payload.url)

      state.tabManager[action.payload.tabId] = newUrl.origin
    },
    tabManagerDelete: (state, action) => {
      delete state.tabManager[action.payload]
      const newtabManage = Object.assign({}, state.tabManager)

      state.tabManager = newtabManage
    },
  },
})
export const { tabManagerUpdate, tabManagerDelete } =
  tabManagerReducerSlice.actions
export default tabManagerReducerSlice.reducer

typescript

redux

google-chrome-extension

redux-toolkit

chrome-extension-manifest-v3

0 Answers

Your Answer

Accepted video resources