Closed ivoscode closed 3 years ago
Found a solution in case someone needs it. Getting instance via ref and then assigning to this.reactInstance.
attachReact(element) {
let instance;
ReactDOM.render(
<SliderCustomComp
ref={(refer) => {
instance = refer;
}}
component={this.component} // These are the component settings if you want to use them to render the component.
value={this.dataValue} // The starting value of the component.
onChange={this.updateValue} // The onChange event to call when the value changes.}
/>,
element,
() => (this.reactInstance = instance)
);
}
In some scenarios (hard to say, sometimes it's just by restarting the server or going back and forth via URL), the ref
will remain as null
, as newer versions of React
may render the component asynchronously.
Check this #327 for the newer method to attach ref
. It appears to have fewer encounters of the null
problem for me.
Environment
Please provide as many details as you can:
Expected behavior
I have a custom slider component. Using it in FormBuilder and expecting it to show up in Form and displaying data from submission if provided.
Observed behavior
Custom component works fine in the FormBuilder. It also shows up in Form and is able to submit data. The only problem I cannot set value from form submission, shows only the default value. In the FormBuilder the attachReact is returning an instance which is later needed by setValue function in ReactComponent.js. On the Form it does not. I believe that is a cause of the problem but not sure how to fix it.
Example
This is a console log from FormBuilder. I noticed it does not get the instance right away but it seems the error is causing to execute redraw function and it gets the instance. On the Form it logs out