Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

465
Vistas
La función de envío de UseReducer arroja un error inesperado: se esperaban 0 argumentos, pero se obtuvo 1

No pude encontrar ninguna respuesta relacionada, la única estaba relacionada directamente con Redux, por lo que hice una pregunta que puede parecer obvia para algunos de ustedes. En cuanto a mi código, parece que todo es correcto, pero tengo problemas con el siguiente error: se esperaban 0 argumentos, pero obtuve 1

Código:

 // An enum with all the types of actions to use in our reducer enum ActionType { INCREASE = 'INCREASE', } // An interface for our actions interface Action { types: ActionType; payload: number; } // An interface for our state interface allState { playersNumber: number, playerData: string } const reducer : any = (state : allState, action : Action) => { switch (action.types) { case ActionType.INCREASE: return { playersNumber: state.playersNumber + 5} } } const initialState = { playersNumber : 0, playerData: "" } const App : FC<any> = () => { const [responseData , setResponseData] = useState<Array<object>>([]); const [state, dispatch] = useReducer(reducer, initialState); // Fetching data with Axios const fetchingData = async () => { const response = await axios.get<Array<object>>('http://localhost:3006/lfy'); setResponseData(response.data); console.log(response.data.length); dispatch({type: ActionType.INCREASE}) } useEffect(() => { fetchingData(); }, []); return ( <Routes> {console.log(state)} <Route path="/" element={<Home />} /> </Routes> ); } export default App;

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

¡Estás ahí! Solo hay algunas cosas que arreglar. Primero, debe eliminar el tipo cualquiera del reductor y devolver siempre el estado completo dentro de la función:

 const reducer = (state : allState, action : Action) => { switch (action.types) { case ActionType.INCREASE: return {...state, playersNumber: state.playersNumber + 5}; // use the shallow copy for the state so you make sure to not replace it completely default: return state; } }

En última instancia, cuando llama al despacho, escribió tipo en lugar de tipos y tampoco pasó la carga útil. Si la carga útil es opcional, debe configurarla como opcional en la interfaz:

 interface Action { types: ActionType; payload?: number; // note the question mark }
 dispatch({types: ActionType.INCREASE});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda