Function useSharedInput

Hook for creating a shared input. The result is a SharedInput object that can be used to create shared inputs between diagrams, as well as an interface between the diagram and the rest of the app. You should use this hook rather than new SharedInput to ensure that the calling component is re-rendered when the input changes.

A SharedInput can be used within a diagram by calling DiagramBuilder.prototype.addSharedInput.

const myInput = db.sharedInput(mySharedInput);

Shared inputs can also be set and get from outside the diagram:

myInput.set(5);
console.log(myInput.get()); // 5
  • Parameters

    • Optionalinit: number

      What to initialize the input to. Defaults to random sampling, and can be overridden from within a diagram. See DiagramBuilder.prototype.sharedInput.

    • optimized: boolean = false

      Whether the shared input should be optimized. This cannot be changed later, and cannot be overridden from within a diagram. Defaults to false.

    • Optionalname: string

      Optional name for the shared input. If provided, the value can also be retrieved from each diagram using the input with DiagramBuilder.prototype.getInput.

    Returns SharedInput