React Native Redux操作未返回有效负载数据

yhxst69z  于 2023-03-31  发布在  React
关注(0)|答案(1)|浏览(151)

我在将数据从我的action返回到redux时遇到了问题。 我的行动如下:export const getUserProfile = createAsyncThunk( "user/getuserprofile", async (thunkAPI) => { var res, user; const isAuthenticated = localStorage.getItem("isAuthenticated") === "true"; var decodedToken = null; if (isAuthenticated) { const access_token = localStorage.getItem("access_token"); decodedToken = jwt_decode(access_token); user = decodedToken.sub; } try { res = await axios .get(${host}/manageAdmins/getUserProfile/${user}) .then((response) => { return response.data; }); } catch (error) { return thunkAPI.rejectWithValue(error.response.data, { source: "API" }); } } );`

in my reducer I did as follows

 `  {
    builder.addCase(getUserProfile.pending, (state, action) => {
       console.log("pending");
     });
          builder.addCase(getUserProfile.fulfilled, (state, action) => {
       console.log("my payload: ");
       console.log(action.payload);
       state.userProfile = action.payload;
     });
     builder.addCase(getUserProfile.rejected, (state, action) => {
       console.log("rejected");
     });
   },`

当我控制有效负载时,它说undefined.但是当我在action部分控制我的数据时,它有一个我想要的值.问题是它不响应reducer的有效负载.当状态被满足时,是否有其他方法返回数据?我已经尝试了**fulfillWithValue(值, meta)**我已经从文档中看到.但不工作.有人请帮助我在做.这.我很感激!`

pdsfdshx

pdsfdshx1#

您需要return res-当前您正在接收该数据,但未对其执行任何操作。

相关问题