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
useMemo documentation #52
Conversation
Is what I wrote true? If so then I think this is the best technique for preventing Hook components from re-rendering and we should explain that.
If a component is re-rendered with new props, it's going to re-render.
This is how React works in JavaScript, but it's not how this PureScript wrapper works. Notice the |
I think this is what I was trying to say, but you put it better. What do you mean by “if you know”? We know that it is always true that “a child component re-renders every time you pass it a new reference, even when the value is equal, you can use |
Oh, maybe we don't know that. Because React probably assumes that our props object is mutable, so even when we pass the same-by-reference props object again, it might re-render? Is there a way prevent a child component from re-rendering if the child component’s props are equal-by-value (but possibly not equal-by-reference) to the props from the last render? |
If the child component uses one of its props to control side effects. Ideally, if it's written in PS and you don't have tons of re-renders happening this should just work as expected. This is because both parent and child will be worrying about PS value equality (
React props are immutable by convention, same as state.
|
This is memo. It's a little awkward to use in PS since these are very JS/non-functional concepts, and it is side effecting for the same reason component creation is.. but sometimes it's what you need. |
If this library did have docs, this would all be in an "edge-case performance optimization" section 😅 |
Okay thank you! |
You could also do this if using child <- useMemo props \_ -> renderChild props
pure child
-- ^ only rebuilds children when props value equality changes |
Is what I wrote true? If so then I think this is the best technique for preventing Hook components from re-rendering and we should explain that.