react native t comb form error string ref "input" React.createRef()

346 Views Asked by At

I have the following form in my render function:

<Form ref={this.formRef} type={SetupOne} options={options} value={this.state.value}/>

I create the ref in my constructor in the top:

this.formRef = React.createRef();

Then I retrieve the value like so:

if (this.formRef && this.formRef.current) {
    const temp = this.formRef.current.getValue();
}

But I get the following error:

ERROR Warning: Component "Textbox" contains the string ref "input". Support for string refs will be > removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref

The error leads me to the line in code where my form is:

in Form (at NewSetup.js:191)

So I am doing it according to the react native docs: https://reactjs.org/docs/refs-and-the-dom.html#creating-refs

That is why I do not understand this error. Has somebody an idea what I am doing wrong?

My react version:

react-native-cli: 2.0.1 react-native: 0.64.0

Thanks for the help!

That is how I am using t comb:

import t from 'tcomb-form-native';
const Form = t.form.Form;
  let SetupOne = t.struct({
        name: t.maybe(t.String),
        nameSub: t.maybe(t.String)
    });
    let options = {
        fields: {
            name: {
                placeholder: 'Bike Name',
                stylesheet: stylesheet
            },
            nameSub: {
                placeholder: 'Location Name',
                stylesheet: stylesheet
            },
            stylesheet: formStyles,
        }
    }

And my state in the constructor:

  this.state = {
     value: {
        name: 'Name',
        nameSub: 'Location'
     },

(This only happens one time after the android build)

0

There are 0 best solutions below