我通过api调用在运行时获取资源。我有一个创建资源的create
视图。如何重新加载react-admin redux store
以便使用新资源更新侧栏?
我想到了跟随here的例子
const saveWithNote = (values, basePath, redirectTo) => {
console.log('creating new dataset...')
crudCreate('datasets', values, basePath, redirectTo);
}
我的想法是在这里触发一些可能触发存储状态更改并重新加载页面的操作,但是我收到错误
TypeError: Cannot read property 'type' of undefined
(anonymous function)
/form/formMiddleware.js:21
18 | var previousLocation;
19 | return function (next) {
20 | return function (action) {
> 21 | if (action.type !== LOCATION_CHANGE || action.payload.state && action.payload.state.skipFormReset) {
| ^ 22 | return next(action);
23 | } // history allows one to redirect to the same location which can happen
24 | // when using a special menu for a create page for instance. In this case,
这是我的工具栏
const DatasetCreateToolbar = props => {
return (
<Toolbar {...props} >
<SaveWithNoteButton
label=" Save "
redirect="list"
submitOnEnter={false}
variant="flat"
/>
</Toolbar>
)
};
代码的其余部分与示例link相同
是否有更好的方法来触发商店重新加载以使我的侧边栏显示创建的新资源?
我弄清楚为什么我会收到错误。
const saveWithNote = (values, basePath, redirectTo) => {
console.log('creating new dataset...')
crudCreate('datasets', values, basePath, redirectTo);
}
我正在调用crudCreate
函数而不是返回它。
代码应该是
const saveWithNote = (values, basePath, redirectTo) => {
console.log('creating new dataset...')
return crudCreate('datasets', values, basePath, redirectTo);
}
我仍然不知道如何刷新我的商店并重新加载侧边栏