useConfig

useConfig is a helper hook that will return the plugin config

How to use

import { Plugin } from '@root'

const MyCustomComponent = () => {
    const config = Plugin.useConfig()
    
    return (
        <div>
            <p>title: {config.title}</p>
        </div>
    )
}

export default MyCustomComponent

useConfig accepts a selector as an argument to select a part of the config instead of returning all the config object

Let's say that your config looks something like this:

{
    [...]
    
    service: {
        endpoint: "http://my-awsome-service.com",
        credentials: {
            username: "mr.awesome",
            password: "supper-secret"
        }
    }
    
    [...]
}

And you want to use the service object in your code:

import { Plugin } from '@root'
import { useEffect } from 'react'

const MyCustomComponent = () => {
    const service = Plugin.useConfig(config => config.service)
    
    useEffect(() => {
        connect(service.endpoint, service.credentials})
    }, [])
}

export default MyCustomComponent

Last updated