Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
Using this in redux initial state?

I want to set certain property of initial state to be relative to other property. So I used this inside of it.

const initialState = {
  canvas_1: {
    canvasName: "canvas_1",
    top: 500,
    left: 600,
    width: 390,
    height: 800,
    xAxisSnap: [0, this.width / 2, this.width],   <-- here
    yAxisSnap: [0, this.height / 2, this.height], <-- here
    selectedShapes: [],
    children: ["hi"],
  },
};

const canvasSlice = createSlice({
  name: "canvas",
  initialState: initialState,
  reducers: {},
});

export const selectShapesOnCanvas = (state) => state.canvas.present.children;

export const {} = canvasSlice.actions;

export default canvasSlice.reducer;

But this is what I got in return from webpack.

var initialState = {
  canvas_1: {
    canvasName: "canvas_1",
    top: 500,
    left: 600,
    width: 390,
    height: 800,
    xAxisSnap: [0, undefined.width / 2, undefined.width],   <-- here
    yAxisSnap: [0, undefined.height / 2, undefined.height], <-- here
    selectedShapes: [],
    children: ["hi"]
  }
};
var canvasSlice = (0,_reduxjs_toolkit__WEBPACK_IMPORTED_MODULE_0__.createSlice)({
  name: "canvas",
  initialState: initialState,
  reducers: {}
});
var selectShapesOnCanvas = function selectShapesOnCanvas(state) {
  return state.canvas.present.children;
};

_objectDestructuringEmpty(canvasSlice.actions);


/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (canvasSlice.reducer);

Am I using this the wrong way, or is it not allowed to use this in RTK?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda