This module provides the possibility for reusing standard and custom React hooks. One function for creating a container with use-between hooks implementation inside.
import { useState, useEffect } from "react";
import { value, useLocal} from "realar";
import { rehook } from "realar-rehook';
class Logic {
a = value("");
b = rehook(() => {
const [name, setName] = useState("");
// And possible to realar logic here
useEffect(() => (
this.a.watch(setName)
), []);
useEffect(() => this.a.set(name), [name]);
// The useEffect should be run synchronously because we don't have mount/unmount component phase
return {
name,
setName
}
});
constructor() {
this.b.val.setName("Joe");
}
}
const Comp = () => {
const logic = useLocal(Logic);
return (
<p>{logic.b.val.name} - {logic.a.val}</p>
)
}
And I can implement React compatibility mode
const hooks = rehook.compat(() => {
console.log(1);
useEffect(() => console.log(3), []);
console.log(2);
// And support the useLayoutEffect as alias for useEffect
});
realar-rehook or realar-rehooks
This module provides the possibility for reusing standard and custom React hooks. One function for creating a container with use-between hooks implementation inside.
And I can implement React compatibility mode