Realar
Reactive state manager for React.
Usage
import React from "react";
import { unit, useUnit } from "realar";
import axios from "axios";
const TodosUnit = unit({
todos: [],
async fetch() {
const { data } = await axios.get("/api/todos");
this.todos = data;
},
constructor() {
this.fetch();
}
});
const App = () => {
const { todos } = useUnit(TodosUnit);
return (
<ul>{todos.map((todo) => <li>{todo.text}</li>)}</ul>
);
};
Tutorials
Glossary
- unit
- useUnit
- changed
- useService
- service
- Service
- event
- call
- signal
- Zone
- mock
- unmock
- ready
Installation
npm i -P realar
yarn add realar
Update your babel config:
module.exports = {
"plugins": [
"realar/babel"
]
}
And to wrap your react-dom
render code, to realar ready
function:
import React from "react";
import { render } from "react-dom";
import { ready } from "realar";
import { App } from "./app";
ready(() => render(<App />, document.getElementById("root")));
Enjoy!