Iconify for React function: addAPIProvider
This tutorial is part of Iconify for React functions tutorial.
Function addAPIProvider() adds API provider.
Make sure you call it before retrieving icons from API provider, otherwise the component will fail to retrieve icons. If you are not sure about execution order of your code, you can also use global variable IconifyProviders to set API providers configuration before loading the component in a separate script. See API providers documentation for details.
API providers
API providers allow using icons from multiple API servers in the same document. For example, you can use default Iconify icons and custom icons from IconScout or Icons8 or custom API.
Public API
@my-icons
@icons8
mdi-light:home
@my-icons:line-24:home
@icons8:ios:home
To support providers, the syntax for icon names has been extended. Icon names in Iconify icon components have 3 parts:
All parts are separated by ":", provider is optional and can be skipped if empty.
Examples:
- my-icons". Icon name for that provider is . : icon is retrieved from provider "
- : icon does not have provider, so provider is empty. Empty value is used for public Iconify API.
Usage
The function has the following parameters:
- provider, string. Provider ID.
- config, APIConfig. API configuration object.
Example
import { addAPIProvider, Icon } from '@iconify/react';
addAPIProvider('local', {
// Array of host names
resources: ['http://localhost:3000'],
});
// Demo using provider in icon name
export function renderHomeIcon() {
return <Icon icon="@local:material-icons:home" />;
}
See API providers documentation for details.