Redux 如何访问thunk操作并从组件库中分派它?
我正在开发一个组件库,我想分派一个操作,而不是绕过函数到我的组件 有什么办法吗 从现在起我就可以这样写了Redux 如何访问thunk操作并从组件库中分派它?,redux,Redux,我正在开发一个组件库,我想分派一个操作,而不是绕过函数到我的组件 有什么办法吗 从现在起我就可以这样写了 const fetchImage = (url) => async () => { try { const res = await fetch(url, { method: "GET", }); const address = await res.json(); dispatch({
const fetchImage = (url) => async () => {
try {
const res = await fetch(url, {
method: "GET",
});
const address = await res.json();
dispatch({ type: "GET_ACCOUNT_IMAGE", address });
} catch (err) {
console.log("error");
}
};
但实际上我希望它能像:
dispatch(toggleTodo(todoId));
由于某种原因,我不能直接传递函数。
有什么想法吗