React hooks for @residualeffect/reactor
Installation can be accomplished using npm:
npm install @residualeffect/rereactor
Implement your application logic using reactor. For example:
import { Observable, Computed } from "@residualeffect/reactor";
export const t = new Observable(3);
export const c = new Computed(() => t.Value * 2);
export function DoSomething() {
t.Value = t.Value + 1;
}
And then utilize your application logic in a react component:
import { useObservable, useComputed } from "@residualeffect/rereactor";
const ExampleComponent: React.FC = () => {
const observedValue = useObservable(t);
const observedComputed = useObservable(c);
const inlineComputed = useComputed(() => t.Value + 1);
return (
<>
<div>Value: {observedValue}</div>
<div>Computed Value: {observedComputed}</div>
<div>Generated Computed: {inlineComputed}</div>
<button onClick={DoSomething}>Go</button>
</>
);
};
rereactor is freely distributable under the terms of the MIT License.