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

breaking: make it compatible with memo and react compiler #202

Merged
merged 12 commits into from
Apr 29, 2024

Conversation

dai-shi
Copy link
Owner

@dai-shi dai-shi commented Mar 2, 2024

  • impl
  • docs

Copy link

codesandbox-ci bot commented Mar 6, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@dai-shi
Copy link
Owner Author

dai-shi commented Mar 6, 2024

@dai-shi
Copy link
Owner Author

dai-shi commented Mar 8, 2024

@dai-shi dai-shi linked an issue Mar 12, 2024 that may be closed by this pull request
@grumd
Copy link

grumd commented Mar 23, 2024

I just tried beta.3 in our repo from work. Admittedly we haven't used "memo" from react-tracked, only "createContainer" to avoid extra rerenders.

Everything works just like before, avoiding any extra rerenders. I haven't found any issues with 2.0.

Not sure how common my use-case is but we do something like this, putting the update function into the state object itself:

const useFormStateValue = ({ state }) => {
  return [state, _.noop];
};

const { Provider, useTrackedState } = createContainer(useFormStateValue);

const Form = ({ values, setValues }) => {
  return (
    <Provider state={{ values, setValues }}>
      {...}
    </Provider>
  );
} 

Form components like radiobuttons and text boxes then use useTrackedState and get their value via values.foo. With react-tracked only the edited fields rerender and the rest of the form doesn't. Some of the fields can even have weird accessors like _.get(values, 'foo[0].bar') and it still works.

@dai-shi
Copy link
Owner Author

dai-shi commented Mar 23, 2024

Thanks for confirming. Yes, the core change in this PR is subtle, and unless people use memo from RT (which is fairly rare, I guess), it should be fine.

@dai-shi dai-shi merged commit 0542bec into main Apr 29, 2024
3 checks passed
@dai-shi dai-shi deleted the compatible-with-memo branch April 29, 2024 12:10
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

Successfully merging this pull request may close these issues.

React Compiler and tracking
2 participants