-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
createAsyncThunk创建的action无法使用dispatch #15517
Comments
解决方法: |
感谢!按你的解决方法成功运行了。 不过是否应该从Taro框架本身引入才更好呢。 |
我按照seekerliu <https://github.com/seekerliu> 提供的解决方案已经可以正常使用了。
… On May 8, 2024, at 15:40, 悟 ***@***.***> wrote:
兄弟,我的不是报错,而是无法捕捉结果。不知道是啥原因,你们之前使用成功了吗?
Taro v3.6.28
extraReducers: (builder) => {
builder.addCase(fetchUser.pending, (state, action) => {
console.log(action)
});
builder.addCase(fetchUser.rejected, (state, action) => {
console.log(action)
});
// Add reducers for additional action types here, and handle loading state as needed
builder.addCase(fetchUser.fulfilled, (state, action) => {
console.log('success', action)
})
}
—
Reply to this email directly, view it on GitHub <#15517 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AFA7VLX6G2AEYL7MJBD25DLZBHJH5AVCNFSM6AAAAABGIQ5H7KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJZHE2DONJSGM>.
You are receiving this because you authored the thread.
|
@hikzhang 我遇到的问题是,模拟器正常,真机调试dispatch之后action没有执行。我的是抖音小程序。 |
装了以后直接白屏了
|
重新启动看看呢?似乎有些编译缓存不会被更新到。
… On May 17, 2024, at 09:57, 悟 ***@***.***> wrote:
装了以后直接白屏了
解决方法: 1,安装这俩包:yet-another-abortcontroller-polyfill,event-target-polyfill 2,app.js import: import 'event-target-polyfill'; import 'yet-another-abortcontroller-polyfill';
—
Reply to this email directly, view it on GitHub <#15517 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AFA7VLTSE5UEZNZGBY2JCJTZCVPY3AVCNFSM6AAAAABGIQ5H7KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJWGQ4DSOJVG4>.
You are receiving this because you were mentioned.
|
遇到了同样的问题,感谢 @seekerliu |
解决了吗,我也是装完白屏 |
我放弃了,移除了redux |
我这边解决了,后面遇到的同学可以参考,微信小程序应该是可以通过上述的polyfill方案解决
|
现在好多库都有依赖 |
Great, this solved my problem. Inspired by you, I listed out my code. import {createAsyncThunk, createSlice} from '@reduxjs/toolkit';
const countSlice = createSlice({
name: 'count',
initialState: 0,
reducers: {
increment(state, action) {
return state + action.payload;
},
decrement(state, action) {
return state - action.payload;
},
},
});
export const { increment, decrement } = countSlice.actions;
export default countSlice.reducer;
// mock time delay
export const delay = (sec) => {
return new Promise(resolve => setTimeout(resolve, sec * 1000));
}
// Async action creator
export const asyncIncrement = (val) => async dispatch => {
console.log('asyncIncrement start');
await delay(2);
dispatch(increment(val));
console.log('asyncIncrement end');
};
// dispatch
const handleAsync = () => {
dispatch(asyncIncrement(3))
} |
相关平台
微信小程序
小程序基础库: 3.4.1
使用框架: React
复现步骤
期望结果
foo定义的async functionf
实际结果
执行时报错:AbortController is not defined
环境信息
补充信息
实际taro版本是3.6.26(无可选项)
The text was updated successfully, but these errors were encountered: