Satpal Singh
Satpal Singh

Reputation: 29

Can't modify storage LiveObject while using liveblocks

I am trying to implement a storage LiveObject, when I try to modify it using set method, inside useMutation hook, it gives error "TypeError: thisCentralCard.set is not a function" :

Error page screenchot from nextjs15

Below is the useMutation hook I tried implementing, which is similar to the example shown in liveblocks storage tutorial.

const updateCentralCard = useMutation(({ storage }, newCard: Card) => {
    const thisCentralCard = storage.get("centralCard") as LiveObject<{color: string, value: string}>;
    console.log(thisCentralCard)
    
    thisCentralCard.set("color", newCard.color);
    thisCentralCard.set("value", newCard.value);
  }, []);

in above code, console.log() works as expected, which means get() is working fine

I have defined the object like this :

//liveblocks.config.ts
Storage: {
      centralCard: LiveObject<{
        color: string;
        value: string;
      }>
    };

I also initialize its value in RoomProvider, so nothing wrong here I hope : ->

< RoomProvider
id = 'testRoomId'
initialStorage = {
    {
      centralCard: new LiveObject < {
        color: 'blue',
        value: '4'
      } > ,
    }
  } >
  <
  ClientSideSuspense fallback = { < div > Loading… < /div>}> 
  <Room / >
    </ClientSideSuspense> 
    </RoomProvider>

Upvotes: 1

Views: 16

Answers (0)

Related Questions