Can anyone explain how to use setControlContextData for defaultValue?

Would be nice if anyone explains how to use setControlContextData for defaultValue prop. It works for type: choice for example but I have the error when I use it with the type: string .

Code example I want to have (it happens in registerComponent):

props: {  
  string:{      
      type: "string",
      defaultValue: (props, ctx) => {
        return ctx.title
      },
  }

Is it possible to make it work with defaultValue for example?

I set up the title with help of next function in Comp:

  setControlContextData?.({
    title: "title", (for choice I use array type)
  })

Thanks for helping!

Hi, can you instead use normal react destructuring defaults for props? Or do you have some more elaboration on what you are trying to do?

Control context data is just a way for the component to communicate any information to the sidebar controls for any purpose.

One purpose can be to influence what is shown in the controls. That’s what the choice option function is for. You can also specify these prop control functions for things like the control’s visibility.

However, default value is not just about how the control appears. Default value is what is actually passed as the prop value as soon as you insert the component into the tree. So it is fixed and unchanging forever - a component should not be able to conditionally influence what props are passed into it from its parent.