1.0.0 • Published 5 months ago

@iotopen/react-lynx v1.0.0

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

React Lynx

This is a React hooks wrapper for the node-lynx library. This library exposes most API-calls as hooks that return objects with named properties. It also includes Contexts that can be used to handle Lynx-connection and current user.

All hooks need to be used withing the LynxProvider context.

Install

npm install --save @iotopen/react-lynx

Usage

Create a LynxProvider to wrap all components using the hooks:

const key = 'abcdef123456789abcdef123456789';

const App = () => {
    return (
        <LynxProvider apiKey={key} apiURL={'https://lynx.iotopen.se'}>
            <MyComponent/>
        </LynxProvider>
    );
};

Then the hooks can be used in MyComponent:

import {useInstallations} from '@iotopen/react-lynx';

const MyComponent = () => {
    const {loading, error, installations, refresh} = useInstallations();

    return (
        <div>
            {loading && <h2>Loading installations...</h2>}
            {!loading && <ul>
                {installations.map(i => <li>i.name</li>)}
            </ul>}
        </div>
    );
};
1.0.0

5 months ago