I am desperately googling and stackoverflowing for hours "How to use multiple data providers with React-admin". I have found many things expect what I really need. How to use dynamically firebase data provider + custom data provider with React admin v3? I use react-admin-firebase for posts and also need to use our custom api for users listing.
This is what I've tried in many different ways (if-else, switch statements etc.):
For Example:
import { dataProvider as firebaseProvider } from "./firebase/firebase.utils";
import { usersMockData } from './api/mockData';
const superDataProvider = (type, resource, params) => {
if (resource === 'users') {
return new Promise(resolve => resolve(usersMockData));
}
return firebaseProvider;
};
<Admin
title="My site"
authProvider={authProvider}
dataProvider={superDataProvider}
loginPage={LoginPage}
>
<Resource
name="posts"
options={{ label: "Posts" }}
list={PostsList}
edit={PostsEdit}
show={PostsShow}
create={PostsCreate}
icon={PostsIcon}
/>
<Resource
name="users"
options={{ label: "Users" }}
list={usersList}
show={usersShow}
icon={usersIcon}
/>
</Admin>
// Output error when I try to reach page with posts from firebase: The dataProvider threw an error. It should return a rejected Promise instead.
Actually, users are loaded, but posts from firebase are not. Interesting fact is, when I use directly firebaseProvider in Admin prop, posts listing's working. WTF? Thanks so much
Oh, come on Connor! Reason why it's not working is so simple! You're just returning firebaseProvider, instead of calling that and return THE RESULT! So try this code and it will definitely easy-peasy work!
const superDataProvider = (type, resource, params) => {
if (resource === 'users') {
return new Promise(resolve => resolve(usersMockData));
}
return firebaseProvider(type, resource, params);
};