Use dispatch inside dataProvider react-admin

366 views Asked by At

so i need call dispatch inside dataProvider to update state uploadProgress for upload video in my form, i already using customReducers in

//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 />

and iam using connect from react-redux to send state as props for my page component

const mapStateToProps = (state) => ({ uploadProgress: state.uploadProgress });

export default connect(mapStateToProps)(ContentItemEdit);

i will update uploadProgress state when update or create video_content, run upload processing to storage, that will show progress bar from it and i get some blocking with dataProvider because dataProvider must export as object cant be function to apply connect to call my dispatch, i cant find way to using connect or call store from 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",

1

There are 1 answers

1
François Zaninotto On BEST ANSWER

You can't call dispatch or connect in a dataProvider, as it has no knowledge of React. This is a current limitation of react-admin.