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

220
Visualizações
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 à 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