Skip to main content
Version: 3.xx.xx

useDataProvider

useDataProvider lets you access the dataProvider that was configured in <Refine> component.

This hook is useful when you need to access the dataProvider Data Provider from a child component.

Usage​

Let's say that we have a data provider named default and second data provider named second.

import { Refine } from "@pankod/refine-core";
import dataProvider from "@pankod/refine-simple-rest";


const App: React.FC = () => {

return (
<Refine
dataProvider={{
default: dataProvider("API_URL"),
second: dataProvider("SECOND_API_URL"),
...
}}
/>
);
};

export default App;

Now we can access the default data provider from a child component:

import {
useDataProvider
} from "@pankod/refine-core";

const dataProvider = useDataProvider();

const defaultDataProvider= dataProvider(); // return default data provider
const secondDataProvider= dataProvider("second"); // return second data provider

API​

Properties​

PropertyDescriptionTypeDefault
dataProviderNameThe name of the data provider you want to accessstringdefault

Return value​

DescriptionType
Data ProviderData Provider