Q:

how to send data in GET request header using react and axios to Django rest framework?

i am new to react and axios and i want to know how to send data in my headers using get request
i tried this but it didn't work
** i observed that the request type changed to options in django terminal window **

export const getUserOrders=(userID)=>{
    return dispatch=>{
        dispatch(getUserOrdersStart())
        axios.defaults.headers={
            'Content-Type':'application/json',
            id:userID
        }
        axios.get('http://127.0.0.1:8000/admindashboard/userorders/')
        .then(res=>{
            const order=res.data
            dispatch(getUserOrdersSuccess(order))
        }).catch(err=>{
            getUserOrdersFail(err)
        })
    }
}

A:

You can give the approach below a whirl.
export const getUserOrders = async userId => {
      const header = {
        "Content-Type": "application/json;charset=utf-8",    
      };
      let id = userId;
      const URL = `http://127.0.0.1:8000/admindashboard/userorders/`
      return dispatch => {
        try {
          dispatch(getUserOrdersStart())

           const response = await axios(URL,id, {
            method: "GET",
            mode: "cors",
            headers: header,

          });
          const jsonResponse = response.json();
          dispatch(getUserOrdersSuccess(order))
        } catch (error) {
          setError(error);
        }
      };

