import { Eventrix } from 'eventrix';
import receiversList from './receivers';
const initialState = {
users: [],
};
const eventrixStore = new Eventrix(initialState, receiversList);
export default eventrixStore;
Create receivers to fetch data.
import axios from 'axios';
import { EventsReceiver } from 'eventrix';
const fetchUsersReceiver = new EventsReceiver('fetchUsers', (eventName, eventData, stateManager) => {
return axios.get('https://myDomain.com/users').then(({ data: usersList }) => {
stateManager.setState('users', usersList);
});
});
const receiversList = [fetchUsersReceiver];
export default receiversList;
import { StrictMode } from "react";
import ReactDOM from "react-dom";
import { EventrixProvider } from 'eventrix';
import eventrixStore from './eventrix';
import UsersList from './components/UsersList';
const rootElement = document.getElementById("root");
ReactDOM.render(
<StrictMode>
<EventrixProvider eventrix={eventrixStore}>
<UsersList />
</EventrixProvider>
</StrictMode>,
rootElement
);
After that you can use hooks and hocs in your react app.