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

221
Vistas
Getting @@INIT action after reloading my page using react redux

I'm trying to get a single order by the ID, i'm using dispatch inside useEffect hook ,and i'm getting @@INIT action after reloading the page. This is my reducer :

export const orderDetailsReducer = (state = {orderItems: [], shippingAddress: {}}, action) => {
    switch (action.type){
        case ORDER_DETAILS_REQUEST:
            return {
                ...state,
                loading : true
            }
        
        case ORDER_DETAILS_SUCCESS:
             return{
                 loading : false,
                 order : action.payload
             }
            
        case ORDER_DETAILS_FAIL:
             return{
                 loading : false,
                 error : action.payload
             }

        default:
            return state
    }
 }

And this is the action :

export const getOrderDetails = (id) => async (dispatch, getState) => {
    try{
        dispatch({
            type: ORDER_DETAILS_REQUEST, 
        })

        const { 
            userLogin: { userInfo }
        } = getState()

        const config = {
            headers: {
                'Content-type': 'application/json',
                Authorization: `Bearer ${userInfo.token}`
            }
        }

        const {data} = await axios.get(
            `/api/order/${id}`,
            config
            )

        dispatch({
            type : ORDER_DETAILS_SUCCESS,
            payload : data
        })


    }
    catch(error){
        dispatch({
            type: ORDER_DETAILS_FAIL,
            payload: error.response && error.response.data.detail
                     ? error.response.data.detail
                     : error.detail   
        })
    }
}

And here is a part of my jsx file :

const dispatch = useDispatch()
    const {id} = useParams()

    const orderDetails = useSelector(state => state.orderDetails)
    const {error, loading, order} = orderDetails

 
    useEffect(() => {
        dispatch(getOrderDetails(id))
        
    }, [dispatch, id]);

When i try to fetch data in the UI it shows but when i reload the page it shows me a white page and the action turns to @@INIT.

about 4 years ago · Santiago Trujillo
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