在 dataProvider 中使用 dispatch react-admin
Use dispatch inside dataProvider react-admin
所以我需要在 dataProvider 中调用调度来更新我表单中上传视频的状态 uploadProgress,我已经在
中使用 customReducers
//reducers
const uploadProgress = (previousState = 0, { type, payload }) => {
if (type === "ADD_PROGRESS") {
return payload;
}
return previousState;
};
//Admin
<Admin
dataProvider={dataProvider}
dashboard={Dashboard}
loginPage={LoginPage}
authProvider={authProvider}
history={history}
customReducers={{ uploadProgress }}
layout={Layout}
customRoutes={customRoutes}
> .... <Admin />
并且我使用来自 react-redux 的连接来发送状态作为我的页面组件的道具
const mapStateToProps = (state) => ({ uploadProgress: state.uploadProgress });
export default connect(mapStateToProps)(ContentItemEdit);
我将在更新或创建时更新 uploadProgress 状态 video_content,运行 将处理上传到存储,这将显示进度条并且我使用 dataProvider 遇到一些阻塞,因为 dataProvider 必须导出为对象无法应用连接来调用我的调度,我无法找到使用连接或从 react-admin
调用存储的方法
const dataProvider = {
getList: (resource, params) => Promise,
getOne: (resource, params) => Promise,
getMany: (resource, params) => Promise,
getManyReference: (resource, params) => Promise,
create: (resource, params) => Promise,
update: (resource, params) => Promise,
updateMany: (resource, params) => Promise,
delete: (resource, params) => Promise,
deleteMany: (resource, params) => Promise,
}
"react-admin": "^3.8.3",
您不能在 dataProvider
中调用 dispatch
或 connect
,因为它不了解 React。这是 react-admin 的当前限制。
所以我需要在 dataProvider 中调用调度来更新我表单中上传视频的状态 uploadProgress,我已经在
中使用 customReducers//reducers
const uploadProgress = (previousState = 0, { type, payload }) => {
if (type === "ADD_PROGRESS") {
return payload;
}
return previousState;
};
//Admin
<Admin
dataProvider={dataProvider}
dashboard={Dashboard}
loginPage={LoginPage}
authProvider={authProvider}
history={history}
customReducers={{ uploadProgress }}
layout={Layout}
customRoutes={customRoutes}
> .... <Admin />
并且我使用来自 react-redux 的连接来发送状态作为我的页面组件的道具
const mapStateToProps = (state) => ({ uploadProgress: state.uploadProgress });
export default connect(mapStateToProps)(ContentItemEdit);
我将在更新或创建时更新 uploadProgress 状态 video_content,运行 将处理上传到存储,这将显示进度条并且我使用 dataProvider 遇到一些阻塞,因为 dataProvider 必须导出为对象无法应用连接来调用我的调度,我无法找到使用连接或从 react-admin
调用存储的方法 const dataProvider = {
getList: (resource, params) => Promise,
getOne: (resource, params) => Promise,
getMany: (resource, params) => Promise,
getManyReference: (resource, params) => Promise,
create: (resource, params) => Promise,
update: (resource, params) => Promise,
updateMany: (resource, params) => Promise,
delete: (resource, params) => Promise,
deleteMany: (resource, params) => Promise,
}
"react-admin": "^3.8.3",
您不能在 dataProvider
中调用 dispatch
或 connect
,因为它不了解 React。这是 react-admin 的当前限制。