mobx-keystone
    Preparing search index...

    Function prop

    • Defines a model property, with an optional function to generate a default value if the input snapshot / model creation data is null or undefined.

      Example:

      x: prop(() => 10) // an optional number, with a default value of 10
      x: prop<number[]>(() => []) // an optional number array, with a default empty array

      Type Parameters

      • TValue

        Value type.

      Parameters

      • defaultFn: () => TValue

        Default value generator function.

      Returns OptionalModelProp<TValue>

    • Defines a model property, with an optional default value if the input snapshot / model creation data is null or undefined. You should only use this with primitive values and never with object values (array, model, object, etc).

      Example:

      x: prop(10) // an optional number, with a default value of 10
      

      Type Parameters

      • TValue

        Value type.

      Parameters

      • defaultValue: Exclude<TValue>

        Default primitive value.

      Returns OptionalModelProp<TValue>

    • Defines a model property with no default value.

      Example:

      x: prop<number>() // a required number
      x: prop<number | undefined>() // an optional number, which defaults to undefined

      Type Parameters

      • TValue

        Value type.

      Returns MaybeOptionalModelProp<TValue>