drizzle
drizzle copied to clipboard
How to use multi call approach without react hooks?
On the react-plugin readme, there is a multi call example with hooks. I'm wondering how to do this with cacheCall. All the cacheCall examples only call a single contract method. What if you need to take the result of one call and use the response as parameters for another call? Here is the example:
import React from 'react';
import { drizzleReactHooks } from ''@drizzle/react-plugin';
import Balance from './components/balance';
export default () => {
const { useCacheCall } = drizzleReactHooks.useDrizzle();
const drizzleState = drizzleReactHooks.useDrizzleState(drizzleState => ({
accounts: drizzleState.accounts
}))
return (
<Balance
balance={useCacheCall(['MyToken'], call =>
drizzleState.accounts.reduce(
(sum, account) => sum + (call('MyToken', 'balanceOf', account) || 0),
0
)
)}
/>
);
}
How would you do this without react hooks, using the regular cacheCall approach?
@cayblood In the hook, you can see that hey basically call cacheCall multiple times internally: https://github.com/trufflesuite/drizzle/blob/develop/packages/react-plugin/src/hooks/create-use-cache-call.js#L33
At present, there's nothing built-in to Drizzle that does this for you. So in effect, you'd need to re-write the logic from create-use-cache-call.js where isFunction is true.