useEventrixState

This hook return eventrix state and setState method.

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 { useEventrixState } from 'eventrix';

const UsersList = () => {
    const [users, setUsers] = useEventrixState('users');
    return (
        <div>
            {users.map(user => <div>{user.name}</div>)}
        </div>
    );
}

If you need only some specific data from state you can get exactly what you want. Thanks of that you will receive better performance of your app. Here is an example how to do that.

import React from 'react';
import { useEventrixState } from 'eventrix';

const UserDetails = () => {
    const [name] = useEventrixState('currentUser.name');
    const [age] = useEventrixState('currentUser.age');
    return (
        <div>
            <div>{name}</div>
            <div>{age}</div>
        </div>
    );
}

Last updated