byte-fe / react-model

The next generation state management library for React
235 stars 22 forks source link

Parent component re-renders #203

Open wzl13211 opened 3 days ago

wzl13211 commented 3 days ago

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.

wzl13211 commented 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 ( <>

{state.num}
</>

); };

export default Child;

import Child from "./Child"; import { useStore } from "@/store/TestStore"; const Test = () => { const [state] = useStore("Test"); console.log("update father"); return (

{state.sex}

); };

export default Test;