fix(react): respect user-provided enabled field in hooks #233
+18
−13
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.
Fix: React hooks should respect enabled field (Issue #224)
Problem
All React hooks in the
@gillsdk/react
package were hardcoding theenabled
field in theiruseQuery
calls, which completely overrode any user-providedenabled
option. This meant that users couldn't control when hooks should run, even when they explicitly setenabled: false
in their options.Example of the problem:
Root Cause
The hooks were using this pattern:
Since
enabled: !!address
came after...options
, it would override anyenabled
value the user provided.Solution
Changed all affected hooks to properly combine the user's
enabled
value with the hook's internal validation logic:How the fix works:
options?.enabled ?? true
- Uses the user'senabled
value, defaults totrue
if not provided&& !!address
- Combines with the hook's internal validation logic using logical ANDenabled: false
, the query won't run regardless of other conditionsenabled
(or sets it totrue
), it behaves exactly as beforeHooks Already Working Correctly
These hooks already respected the user's
enabled
field since they don't override it:useSlot
useLatestBlockhash
useRecentPrioritizationFees
Testing
The fix has been verified with a comprehensive test that covers all scenarios:
Test File:
test_enabled_logic.js
Note
Test file deleted after the expected results.
Test Results:
All test cases pass, confirming that the logic correctly:
enabled: false
settingtrue
whenenabled
is not providedUsage Examples
Before Fix (user's enabled was ignored)
After Fix (user's enabled is respected)
Conditional queries now work properly
Backwards Compatibility
Fully backwards compatible - existing code continues to work exactly as before since:
enabled
is not provided remains the same (true
)