0/24
2. Writing an RPC

Lesson 2: Writing an RPC

In the last lesson you called a server function. Now you'll write one.

live(fn) wraps any function as an RPC endpoint. The first argument is always ctx (the context), followed by whatever arguments the caller passes.

export const myFunc = live((ctx, arg1, arg2) => {
  return arg1 + arg2;
});

The add function is already done. It takes two numbers and returns their sum.

Try it

  1. Create a multiply function that multiplies two numbers
  2. Wrap it with live() and export it
  3. Import it in the component and add a button to test it
WebSocket
0
No messages yet
/