Search code examples
react-nativeref

How to dynamically create refs react native video


How can I create dynamic refs for a list of videos now that using just a string is not acceptable?

For example how to turn this into something dynamic

ref={(ref) => { this.player = ref }}

when you could just do this before

x = ['ref1', 'ref2']
ref={x[index]}

Solution

  • you can try it like this:-

    constructor(props) {
        super(props)
        ....
        this.myInput = [];
      }
    ...
    render() {            // or return depending on your code
        for (i=0;i<=n;i++) {
            ... your code...   // i will go with TextInput for now
            <TextInput
                ref={(input) => {this.myInput[i]=input}}
                multiline={true}
                style={{ padding: 10, fontSize: 15 * myr, alignSelf: 'center', backgroundColor: 'red' }}
                onChangeText={(text) => Email = text}
                placeholder="Email*"
            />
        }
    }