getAction

You can use registered Actions by passing the Action id to getAction method from Plugin-API

How to use

import { Plugin } from '@root'

import {
    useRef,
    useState,
    useCallback
} from 'react'

const Application = () => {
    const fetchAction = useRef(getAction('my-fetch-action'))
    const loggerAction = useRef(getAction('my-logger-action'))

    const [data, setData] = useState(null)

    const handleOnLoadMore = useCallback(() => {
        fetchAction.current('www.my-data.endpoint.com/json')
            .then(payload => {
                setData(payload)
            })
            .catch(error => {
                loggerAction.current(error)
            })
    }, [])

    return (
        <button onClick={handleOnLoadMore}>
            {'Load more'}
        </button>
    )
}

export {
    Application
}

Last updated