This repository was archived by the owner on Feb 9, 2024. It is now read-only.
Add util helpers
Add helper functions to easily pick deeply nested values returned by contract messages.
pickDecodedpickErrorpickResultOkpickResultErr
See useink/utils documentation for details.
Helper functions that will reduce if statements and React code by up to 15%.
Example
// Let's pretend this returns a Result<{ Ok?: { flipped: true }, Err?: { Womp: string }> on each new block
const get = useCallSubscription(flipper, 'get')
// Some of the new pick* functions
const okValue = pickResultOk(get.result); // This is { flipped: true } or undefined
const errValue = pickResultErr(get.result); // This is { Err: { Womp: string } or undefined
// INSTEAD OF DOING the deeply nested Choo Choo train from hell 🚊🔥
get?.result?.ok ? get.result.value.decoded?.Ok : undefined
get?.result?.ok ? undefined : get.result.value.decoded?.Err