How is the correct way to have multiple dataProviders in react-admin?

前端 未结 3 1762
忘掉有多难
忘掉有多难 2021-01-02 17:25

I\'m trying to use multiple dataproviders in a react-admin project but I have an error:

Warning: Missing translation for key: \"dataProvider is not a functio         


        
3条回答
  •  难免孤独
    2021-01-02 18:03

    You're not calling the dataProvider you found, you're calling the mapping object from your array. You can fix it like this:

    import simpleRestProvider from 'ra-data-simple-rest';
    
    const dataProviders = [
      { dataProvider: simpleRestProvider('http://path.to.foo.api1'), resources: ['users1'] },
      { dataProvider: simpleRestProvider('http://path.to.foo.api2'), resources: ['users2'] },
    ];
    
    export default (type, resource, params) => {
      const dataProviderMapping = dataProviders.find(dp => dp.resources.includes(resource));
      return dataProviderMapping.dataProvider(type, resource, params);
    };
    

提交回复
热议问题