Plugin notes

Passing G to effects

boardgame.io uses Immer internally to help with immutability. That means that inside a move or game hook, G and its contents are wrapped in a Proxy and we’ll run into issues passing it to an effect. (The only exception is if we’re passing a property that is a single literal value like a string, number, or boolean.)

If you want to pass an object or array stored in G when calling an effect, you need to unwrap this proxy to get the plain value. To do this, import and use Immer’s current helper. This will convert the proxied state to a plain JavaScript object.

import { current } from 'immer';

// inside a move
const unproxiedValue = current(G.dice);
ctx.effects.roll(unproxiedValue);

You can also do this directly inside your effects config, so you don’t need to remember this every time the effect gets called.

import { current } from 'immer';

export const config = {
  effects: {
    roll: {
      create: (value) => current(value),
    },
  },
};