DEV Community

Abdullah Javed
Abdullah Javed

Posted on

Fetch data with parameters from async thunk

Want to fetch data by parameters unable to fetch why ??

export const getdataById = createAsyncThunk(
"bus/getdataById",
async (data, { rejectWithValue }) => {
try {
const response = await axios.get(${API_Link}getdatabyId, {
params:{
id: data.id,
},
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},

  },data.id);
  return response.data;
} catch (error) {
  return rejectWithValue(error.response.data.message || error.message);
}
Enter fullscreen mode Exit fullscreen mode

}
);

Top comments (0)