-
Notifications
You must be signed in to change notification settings - Fork 2
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
Revise hooks - adjust which arguments should be reactive #552
Comments
tjcouch-sil
added
the
needs design
Waiting on further design decisions and clarification
label
Nov 14, 2023
19 tasks
tjcouch-sil
removed
the
needs design
Waiting on further design decisions and clarification
label
Dec 11, 2023
tjcouch-sil
changed the title
Revise hooks - consider which arguments should be reactive
Revise hooks - djust which arguments should be reactive
Dec 14, 2023
tjcouch-sil
changed the title
Revise hooks - djust which arguments should be reactive
Revise hooks - adjust which arguments should be reactive
Dec 14, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
User Story
As an extension developer, I want the React hooks exposed on the
papi
to make sense and have parameters with appropriate reactivity to existing React hooks and consensus so that I can use hooks effectively without bugs or unnecessary rerenders.Description
Update our hooks in the following ways:
use-setting.hook.ts
anduse-data.hook.ts
currently retrieve the new value when the key/selector is changeduse-webview-state.hook.ts
touse-web-view-state.hook.ts
use-web-view-state.hook.ts
get the new value at the key when the key is changed instead of overwriting the value at the new key when the key is changed. Currently, web view state keeps the current value and overwrites the value at the new key.defaultValue
andoptions
parameters refs (useRef
) so they are not included in dependency arrays (matchesdefaultValue
better with how it works inuseState
). Therefore, they will not cause likely unintended recalculations of dependency-based hooks likeuseEffect
anduseCallback
. Using refs for these does, however, allow callbacks and other things that can re-initiate a need for adefaultValue
to honor the most current value of these parameters. In some contexts, this is simply to be expected from these parameters. However, in other cases, it is not naturally expected but is still a benefit. As such, we should document accordingly: the JSDoc for each of these parameters should have a new paragraph with "Note: this parameter is internally assigned to aref
, so changing it will not cause any hooks to re-run with its new value." along with the implications of using a ref for this parameter specifically in each context. Indicate very clearly in the JSDoc that these parameters are NOT listened to in dependency arrays; therefore another argument must be changed or the component must be remounted in order for thedefaultValue
to be updated.defaultState
not reactive inuse-setting.hook.ts
useSetting
for practice with the others: In the current implementation ofuseSetting
,defaultValue
is a dependency on auseEffect
and auseCallback
. WhendefaultValue
is changed to be a ref, changingdefaultValue
will no longer cause theuseEffect
to re-fetch the setting and cause the returned values to change (which could cause more recalculations or rerenders depending on how a component using this hook uses it). This means changingdefaultValue
will no longer update the returned state to the newdefaultValue
if it is currently on the previousdefaultValue
. However, since it is a ref, runningsetSetting(undefined)
will still set the setting to the newestdefaultValue
.ref
, so changing it will not cause any hooks to re-run with its new value. RunningsetSetting(undefined)
will always use the latestdefaultValue
. However, ifdefaultValue
is changed while a setting isundefined
, the returned setting value will not be updated to the newdefaultValue
."defaultValue
not reactive inuse-promise.hook.ts
subscriberOptions
increate-use-data-hook.util.ts
(and make sure to update the JSDocs foruseData
anduseProjectData
)use-promise.hook.ts
'spreserveValue
boolean to anoptions
object withpreserveValue
inside of it, and make thatoptions
object a refpreserveValue
, so something like "Note: this parameter is internally assigned to aref
, so changing it will not cause any hooks to re-run with its new value. However, its latest value will be used appropriately." works for this oneuseDialogCallback
to accept a response callback and a reject callback instead of having bunches of possibly unnecessary states/rerenders and complicated apidialogType
,options
,resolveCallback
,rejectCallback?
dialogType
is a ref - please include note in JSDoc as mentioned aboveoptions
is a ref - please include note in JSDoc as mentioned aboveresolveCallback
runs with the promise's resolved value. Reactive - run the latest when the dialog call resolvesresponse
,dialogType
,options
(pass in thedialogType
andoptions
that were sent to it)rejectCallback
runs with the promise's rejected value if an error occurs (catch). Reactive - run the latest when the dialog call rejectserrorMessage
,dialogType
,options
(pass in thedialogType
andoptions
that were sent to it)showDialog
-showDialog()
- function to run to show the dialogREADME.md
in the hooks directory that explains these guiding principles around making hooksThe text was updated successfully, but these errors were encountered: