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

105
Visualizações
React-toolkit Cannot read properties of undefined (reading 'type') error

I'm learning redux-toolkit and I wrote sample code, but when using useDisptach method I get "Cannot read properties of undefined (reading 'type')" error. What do you think is the reason for this? I am sharing the code below:

my index.js file:

import Head from "next/head";
import Nav from "../components/nav/Nav";
import { useEffect } from "react";
import { useSelector, useDispatch } from "react-redux";
import detectDevice from "../redux/device";

export default function Home() {
  const dispatch = useDispatch();
  useEffect(() => {
    dispatch(detectDevice());
  }, []);
  return (
    <div>
      <Head>
        <title>Test</title>
        <meta name="description" content="Generated by create next app" />
        <link rel="icon" href="/favicon.ico" />
      </Head>
      <Nav />
    </div>
  );
}

my device.js file:

    import { createSlice } from "@reduxjs/toolkit";
export const deviceSlice = createSlice({
  name: "isMobile",
  initialState: {
    value: false,
  },
  reducers: {
    detectDevice: (state) => {
      state.value = true;
    },
  },
});
export const { detectDevice } = deviceSlice.actions;

export default deviceSlice.reducer;

my store.js file :

    import { configureStore } from "@reduxjs/toolkit";
import detectDevice from "./device";
export default configureStore({
  reducer: {
    isMobile: detectDevice,
  },
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I found where I made a mistake. The import on line 5 in the index.js file should have been like this: import { detectDevice } from "../redux/device";

about 4 years ago · Juan Pablo Isaza Relatório
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