1.0.1-vz • Published 11 months ago

react-use-eventbus-z v1.0.1-vz

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Description

  • Wrapper event bus: eventbus-z
  • busClient: use with SSR

Usage

Install the package

npm install --save react-use-eventbus-z

Import the module in the place you want to use:

import { useEventBusOn, WrapEventBus } from 'react-use-eventbus-z';

Snippet

    import { useEventBusOn, WrapEventBus } from 'react-use-eventbus-z';

    const App = () => {
        useEventBusOn('NAME', (abc, def) => {
            alert('abcd');
        })
        return <Child />;
    }

    const Child = () => {
        return <button onClick={() => WrapEventBus.sendEvent('NAME', 'abc', 1234)}>Abcd</button>
    }
    import { useEventBusOn, WrapEventBus } from 'react-use-eventbus-z';

    const App = () => {
        useEventBusOn('NAME', (resolve, reject, params) => {
            // fetch api
            resolve();
            // reject();
            alert(def);
        })
        return <Child />;
    }

    const Child = () => {
        return <button
            onClick={async () => {
                const results = await WrapEventBus.sendAsyncEvent('NAME', params);
            }}
        >Abcd</button>
    }

Events

See eventbus-z

RUN

LIVE EXAMPLE

License

MIT