Open wzl13211 opened 3 days ago
`import { Model } from "react-model";
// define model const Test = { state: { items: ["Install react-model", "Read github docs", "Build App"], sex: "man", num: 0, }, actions: { setNum: () => (state) => { state.num += 1; }, }, };
// Model Register const { useStore } = Model({ Test }); export { useStore };`
import { useStore } from "@/store/TestStore"; const Child = () => { const [state, actions] = useStore("Test"); console.log("update child"); const handel = async () => { actions.setNum(); }; return ( <>
</>
); };
export default Child;
import Child from "./Child"; import { useStore } from "@/store/TestStore"; const Test = () => { const [state] = useStore("Test"); console.log("update father"); return (
); };
export default Test;
Changing one component causes the other component to render, and both components have unrelated state in the repository, but in reality neither of them matters.