Skip to content
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: make all hooks use the same return type definition #85

Merged
merged 3 commits into from
May 28, 2024

Conversation

helciofranco
Copy link
Member

From now on, our hooks will return T | null, instead of T | undefined | null.
Most of them were already return only the T | null, I've just fixed the missing ones.

Examples

const { wallet } = useWallet(); // wallet is Wallet | null
const { network } = useNetwork(); // network is Network | null
// and so on... Every query hook will return T | null

@helciofranco helciofranco linked an issue May 28, 2024 that may be closed by this pull request
@helciofranco helciofranco self-assigned this May 28, 2024
@helciofranco helciofranco requested a review from a team May 28, 2024 20:17
@helciofranco helciofranco marked this pull request as ready for review May 28, 2024 20:17
Copy link
Contributor

github-actions bot commented May 28, 2024

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 87.8% 324/369
🔴 Branches 48.98% 48/98
🟢 Functions 92.86% 91/98
🟢 Lines 89.17% 321/360

Test suite run success

23 tests passing in 3 suites.

Report generated by 🧪jest coverage report action from 663a8cf

@helciofranco helciofranco merged commit ec0bd2d into main May 28, 2024
8 checks passed
@helciofranco helciofranco deleted the hf/fix/consistent-return branch May 28, 2024 22:16
LuizAsFight pushed a commit that referenced this pull request Jun 4, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @fuels/react@0.21.0

### Minor Changes

- Created useContractRead hook to read contract data from a contract
instance or from a contract id.
If provided Abi is declared with `as const`, hook will dynamically infer
possible method names, as well as the arguments quantity and types for a
selected method, by [@arthurgeron](https://github.com/arthurgeron) (See
[#91](#91))
- - Add `useTransactionResult` hook to get a transaction that has been
executed
- Create a type `UseNamedQueryParams` to allow overriding `select`
function of TanStack Query and our custom `name` property.
    ### Basic usage with `select` function
    ````tsx
    const { receipts } = useTransactionResult({
txId:
'0xd7ad974cdccac8b41132dfe1d2a4219a681af1865f0775f141c4d6201ee428d1',
    query: {
name: 'receipts', // Or anything else (optional, default:
'transactionResult')
    select: (data) => data?.receipts || null,
    },
    });
```, by [@helciofranco](https://github.com/helciofranco) (See
[#94](#94))
    ````
- Adds mutation callbacks, such as `onError` and `onSuccess`, by
[@helciofranco](https://github.com/helciofranco) (See
[#97](#97))
- Provide consistent return types across Fuel hooks, for an easier typed
experience.
Every query hook will now return a `null` value if the query is not
available, instead of `undefined`.
    ### Examples
    ````tsx
    const { wallet } = useWallet(); // wallet is Wallet | null
    const { network } = useNetwork(); // network is Network | null
    // and so on... Every query hook will return T | null
```, by [@helciofranco](https://github.com/helciofranco) (See
[#85](#85))
    ````
- Add `useSendTransaction` hook that allows developers to easily send a
transaction.
    ````tsx
    const { sendTransaction } = useSendTransaction();
    // [...]
const transactionRequest = new ScriptTransactionRequest({}); // Or any
other tx request
    sendTransaction({
address:
'fuel1zs7l8ajg0qgrak3jhhmq3xf3thd8stu535gj7p5fye2578yccjyqcgja3z',
    transaction,
    });
```, by [@helciofranco](https://github.com/helciofranco) (See
[#92](#92))
    ````

## @fuels/playwright-utils@0.21.0

### Patch Changes

- update wallet version to 0.21.0, by
[@LuizAsFight](https://github.com/LuizAsFight) (See
[#98](#98))

## @fuels/assets@0.21.0



## @fuels/changeset@0.21.0



## @fuels/eslint-plugin@0.21.0



## @fuels/jest@0.21.0



## @fuels/local-storage@0.21.0



## @fuels/prettier-config@0.21.0



## @fuels/react-xstore@0.21.0



## @fuels/ts-config@0.21.0



## @fuels/tsup-config@0.21.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consistent return type signature for @fuels/react hooks
2 participants