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

[Advanced React] Master Memoization in React #76

Open
reboottime opened this issue Apr 28, 2024 · 2 comments
Open

[Advanced React] Master Memoization in React #76

reboottime opened this issue Apr 28, 2024 · 2 comments

Comments

@reboottime
Copy link
Owner

No description provided.

@reboottime
Copy link
Owner Author

reboottime commented Apr 28, 2024

Major Concepts

  • Shallow comparison: compare by reference
image
  • Memo funcs

    • useCallback: guarantee a func between always refer to the same reference value between renders
    • useMemo: guarantee a value between always refer to the same value between renders
  • How things work under the hood ( pseudocode)


image

@reboottime
Copy link
Owner Author

reboottime commented Apr 28, 2024

Practices Examples

Example 1: Declare component inside of another component

Declared a component inside of another component, and every re-render brings in a new Input declared

image

As React thinks the Input before and after are two different component, so when Input unmounts and mounts.



Example 2: Apply key property

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant