-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fix: Introduce useFastField React hook #1772
Conversation
I wonder if it would be useful to skip the optimization when there is an error, so that the error can be resolved as soon as possible. (A user might think they still haven't fixed the value until the error goes away) |
@johnrom can you share some pseudo-code for how that might work? |
I might be way overthinking this but: field.onChange = React.useCallback(
meta.error
// if there's an error, just call onChange
? onChange
// am I delusional? do we need to support onChange('string', value) ??
: (
eventOrPath: string | React.ChangeEvent<any>
): void | ((eventOrTextValue: string | React.ChangeEvent<any>) => void) => {
if (isString(eventOrPath)) {
return event => setValue(event.target.value);
} else {
setValue(eventOrPath.target.value);
}
},
[meta.error]
); |
@sparkboom nice!! I have a scenario where I have to use a custom onChange function. Wouldn't be nice if the useFastField also received a custom onChange function as a parameter? |
While this approach is not bad, I personally think that it doesn't help when you want to react to something as you are typing (before you blur). I think that While |
@3nvi I think we'll be able to tackle this in v3 with React Flare |
That's great! Is there an (unofficial & non-bounding) estimation on that? |
I noticed, in the PR's suggested |
@jaredpalmer just came across your note here and it looks like Flare has been abandoned:
|
Good look. Just subscribed. Will follow up with React team directly about next steps
…--
Jared
________________________________
From: John Rom <[email protected]>
Sent: Wednesday, January 8, 2020 12:05 PM
To: jaredpalmer/formik
Cc: Jared Palmer; Mention
Subject: Re: [jaredpalmer/formik] Fix: Introduce useFastField React hook (#1772)
@jaredpalmer<https://github.com/jaredpalmer> just came across your note here and it looks like Flare has been abandoned:
We're not longer working on this particular approach and will be exploring other ways to work with the DOM event system in the future. We've concluded that the "Flare" event system is too high-level an abstraction and we'd like to explore something that is a bit more familiar to developers familiar with the DOM (e.g., addEventListener) and React's existing tools (e.g., hooks). Our goal is still to make it possible for library authors to work with passive events, capture/bubble phase, custom events, and events occurring on the document from within a React function component...while reducing the amount of event-related code needed in ReactDOM. Ultimately building both intermediate abstractions like the Responder Event system and high-level abstractions like useTap (which we prototyped in Flare) should be possible in user-space.
facebook/react#15257<facebook/react#15257>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#1772?email_source=notifications&email_token=AA67IG37HPAQEXLJBYQ4A3DQ4YWXVA5CNFSM4IPH2Z22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEINZTVA#issuecomment-572234196>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AA67IGZF7O6IOQSW4HQEEMDQ4YWXVANCNFSM4IPH2Z2Q>.
|
Hi, @jaredpalmer are there any plans to provide a useFastField hook? The slow performance, specially in IE is a showstopper for me. |
export function useFastField<Val = any>( | ||
props: FieldAttributes<Val> | ||
): [FieldInputProps<Val>, FieldMetaProps<Val>] { | ||
const [field, meta] = useField<Val>(props); |
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.
@sparkboom missing helpers right?
can we release this as |
Another guy here that could benefit from this |
Up? |
you can copy and paste from here https://gist.github.com/sibelius/ccea4d505eb20d0dd08c19716c469093 until this lands |
Looks like approved but somebody is not yet pressing the button? |
@gperez-10pines not at all. None of the solutions are ideal, the performance with Field itself needs to be fixed. FastField was a meh solution in v1. You're free to try various userland solutions, but I don't think Formik will adopt anything until we figure out a real highly optimized method using #2749 or something else. I believe the React team has focused on "abandoning renders" when nothing really changes instead of preventing renders from starting, so has not been focused on optimizing Context which Formik is using and is causing this performance issue. At least that's my impression of the state of things. |
This is correct. However, I'm working on fixing field. Fastfield was a hack for v1 that has no parallel in hooks land. shouldComponentUpdate is different that the implementation here. My progress on fixing this can be seen here #2749 |
This has been implemented in v3 with just the regular |
sorry to dig this up, but @jaredpalmer -- I can't see any reference to a Is this just built in behaviour for the hook? |
Formik died. |
This PR offers an implementation of
useFastField
React hook as a solution for issue #1026 and #671 for Formik's 'next' release. It behaves like a FastField where the state of the field does not update Formik's values and errors model until the user's focus is removed from it providing some optimised behaviour.Included in this PR is
useFastField
hookView rendered docs/api/useFastField.md