Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About Rerendering ,Is it a bug or my usage error,Request help #717

Closed
ljianc opened this issue Apr 23, 2023 Discussed in #716 · 1 comment
Closed

About Rerendering ,Is it a bug or my usage error,Request help #717

ljianc opened this issue Apr 23, 2023 Discussed in #716 · 1 comment

Comments

@ljianc
Copy link

ljianc commented Apr 23, 2023

  1. Index component only access snapshot.loading
  2. Content component only set state .message
  3. Why Index component Rerendering 3 times, My understanding should be 2 times
const state = proxy({ loading: true, message: "" });

function Index() {
  const snapshot = useSnapshot(state);
  const Node = snapshot.loading ? Loading : Content;
  useEffect(() => {
    console.log("Log Index Rerendering");
  });
  useEffect(() => {
    state.loading = false;
  }, []);
  return <Node />;
}

function Loading() {
  return <>loading</>;
}

function Content() {
  useEffect(() => {
    //If this is added,Index Rerendering 3 times
    state.message = "welcome";

    //If this is removed,Index Rerendering 2 times
    //state.message = "welcome";
  }, []);
  return <>test</>;
}
@dai-shi
Copy link
Member

dai-shi commented Apr 23, 2023

Please continue discussion in #716.

@dai-shi dai-shi closed this as completed Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants