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

359
Views
TypeError (0, _index.DEC_NUM) no es una función

Así que recibo este error de que DEC_NUM no es una función. Estoy haciendo un estado de contador usando react-redux. Cuando hago clic en el contador (+), aparece este error.

Imagen de error

Aquí está mi código: Action/index.js

 const INC_NUM = () => { return { type: "INC_NUMBER" }; }; const DEC_NUM = () => { return { type: "DEC_NUMBER" }; }; export default { INC_NUM, DEC_NUM };

Reductor/contraReductor.js

 const counterReducer = (state = 1, action) => { if (action.type === "INC_NUMBER") { console.log("Pressed +"); } else if (action.type === "DEC_NUMBER") { console.log("Pressed -"); } return state; }; export default counterReducer;

Reductor/index.js

 import counter from "./counterReducer"; import { combineReducers } from "redux"; const rootReducer = combineReducers({ counter }); export default rootReducer;

Tienda.js

 import rootReducer from "./Reducer/index"; import { createStore } from "redux"; const store = createStore(rootReducer); export default store;

El código principal App.js

 import "./styles.css"; import { INC_NUM, DEC_NUM } from "./Action/index"; import { useSelector, useDispatch } from "react-redux"; export default function App() { const count = useSelector((state) => state.counter); const dispatch = useDispatch(); return ( <div className="App"> <h1>Reducer Counter</h1> <button onClick={() => { dispatch(DEC_NUM()); }} > - </button> <span>{count}</span> <button // onClick={() => { // dispatch(INC_NUM()); // }} > + </button> </div> ); }

El error principal proviene de este código anterior, solo que DEC_NUM no es la función

índice.js

 import { StrictMode } from "react"; import ReactDOM from "react-dom"; import App from "./App"; import store from "./store"; import { Provider } from "react-redux"; const rootElement = document.getElementById("root"); ReactDOM.render( <StrictMode> <Provider store={store}> <App /> </Provider> </StrictMode>, rootElement );
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simplemente exporta (no por defecto | normal) como ->

 export const INC_NUM = () => { return { type: "INC_NUMBER" }; }; export const DEC_NUM = () => { return { type: "DEC_NUMBER" }; }; ------------- import { INC_NUM, DEC_NUM } from "./Action/index";

Nota: No puede desestructurar exportaciones predeterminadas como esta. Para tu caso, si quieres puedes utilizar:

 const INC_NUM = () => { return { type: "INC_NUMBER" }; }; const DEC_NUM = () => { return { type: "DEC_NUMBER" }; }; export default { INC_NUM, DEC_NUM }; ----------------------- import counterActions from "./Action/index"; const onClick => dispatch(counterActions.INC_NUM())
about 4 years ago · Juan Pablo Isaza Report
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!