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

219
Views
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
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!