@eventListener

This decorator register component method on component did mount as listener in eventrix and unregister when component will unmount.

"eventrixComponent" decorator is required if You want use any of eventrix component decorators

If You want use hooks, hocs or component decorator You must use EventrixProvider in Your application. Go to "EventrixProvider" page in "Context" section for more details.

import React from 'react';
import { eventrixComponent, eventListener } from 'eventrix';

@eventrixComponent
class Counter extends React.Component {
    constructor(...args) {
        super(...args)
        this.state = {
            counter: 0;
        };
    }

    @eventListener('Clients:create.success')
    createCounter(eventData) {
        this.setState({ counter: this.state.counter + 1 });
    };
    
    render() {
        return (
            <div>Created clients number: {this.state.counter}</div>
        );
    }
}

export default Counter;

Last updated