Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Edit in place hook #28924
Edit in place hook #28924
Changes from 8 commits
1ad3f18
3c1191f
6d554ca
044cac4
18ef7af
9793a56
6b2a39b
3c30e6d
0841aa9
a584a12
e98de96
533d7b7
5faf3cc
c8e1ef1
0e19059
0fe9119
5bf4f8e
be80620
dfbe4d6
face180
c9895d0
c2cf674
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isInvalid
andonWrongInput
functions are being omitted from the effect dependencies. I understand it would be annoying to include them there since those props could be passed as inline functions and would trigger the effect on every re-render. But I think we should at least add a comment explaining that the effect will get out of sync if thevalidate
logic is changed whilevalue
remains the same. I remember @ItsJonQ worked on something similar.The local
value
is also omitted from the deps.Can't we just call
onWrongInput
on theonChange
/onBlur
event? It would be much simpler than doing that in an effect.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diegohaz Ah! Are you referring to this
usePropRef
pattern I came up with?https://github.com/ItsJonQ/g2/blob/main/packages/utils/src/hooks/use-prop-ref.js
I haven't tried it, but that seems like that would be simpler 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diegohaz As far as I understand what you mean is that we want to make it possible the component will react if a validation (or error handling) function changes. From my perspective, we can do only two things: add those functions as the dependencies and the component will rerender every time, which will lead to poor performance or to skip these dependencies (with a comment as you suggest) as I think it is an edge case.
Solution with
usePropRef
would not apply here as the component would not react for a function change, please see the sandbox:https://codesandbox.io/s/suspicious-sanne-74lv9?file=/src/App.js
We can use this pattern though, in order to add references to the hooks dependency array and not to make it rerender every time. This will make a code cleaner but the problem will remain the same.
But all in all, if we validate the value only onCommit (see my recent commit) then the entire problem just vanishes 🦩