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

121
Views
El cambio de estado no se refleja en el componente, el estado debería devolver una matriz pero devolver un objeto vacío

Estoy tratando de hacer una aplicación de reacción que use firebase. Después de cambiar el valor de estado en el reductor y devolverlo, no actualiza el valor de los accesorios en consecuencia.

Aquí está mi reductor:

 import { ADD_NOTE, ADD_SUBJECT, ADD_TOPIC, REMOVE_NOTE, REMOVE_SUBJECT, REMOVE_TOPIC, UPDATE_NOTE, UPDATE_SUBJECT, UPDATE_TOPIC, FETCH_ALL_DATA } from '../action/action-types' import { fetchAllSubjects } from '../controller/fetchAllSubjects' const initialState = [] export const reducer = async (state = initialState, action) => { switch(action.type){ case FETCH_ALL_DATA: let data = fetchAllSubjects() await data.then(result => { state = result }) console.log('state : ', state); return state; default: return state } }

Componente en el que estoy tratando de usar el estado:

 import React, {useEffect} from 'react' import { connect } from 'react-redux' import { fetchAllData } from '../action/action' const Subjects = ({data, fetchData}) => { useEffect(() => { fetchData() }, []) return ( <> {JSON.stringify(data)} </> ) } const mapStateToProps = state => ({ data : state }) const mapDispatchToProps = dispatch => ({ fetchData: () => { dispatch(fetchAllData()) } }) export default connect(mapStateToProps, mapDispatchToProps)(Subjects);

Mi aplicación.js:

 import React from 'react' import Subjects from './component/subjects' // redux import { Provider } from 'react-redux' import store from './centralState/store' const App = () => { return( <Provider store={store}> <Subjects /> </Provider> ) } export default App;

y tienda redux aquí:

 import { createStore, combineReducers } from 'redux' import { reducer } from '../reducer/reducer' const rootReducer = combineReducers({ reducer }) const store = createStore(rootReducer) export default store

Primero muestra la salida como:

{"reductor":{}}

en el navegador

y después de algunos milisegundos imprime el estado (que es una matriz de objetos de tamaño 2) en la consola mientras estoy imprimiendo en reductor

Gracias.

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