Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react warning: Each child in an array or iterator should have a unique "key" prop. #276

Closed
iambumblehead opened this issue Nov 15, 2017 · 2 comments

Comments

@iambumblehead
Copy link

I'm seeing a react warning using the latest react-player sources

react-player: 0.25.3
react: 16.1.0

warning.js:33 Warning: Each child in an array or iterator should have a unique "key" prop.

Check the top-level render call using <video>. See https://fb.me/react-warning-keys for more information.
    in source

the stack trace shows this as the only non-react source file associated with the message

render  @  FilePlayer.js:245

and opening that shows this...

      return _react2['default'].createElement(
        Element,
        _extends({
          ref: this.ref,
          src: src,
          style: style,
          preload: 'auto',
          controls: controls,
          loop: loop
        }, config.file.attributes),
        url instanceof Array && url.map(this.renderSource),
        config.file.tracks.map(this.renderTrack)
      );

the ReactPlayer is included in this way

            <ReactPlayer
                ref={this.ref.bind( this )}
                url={[ { src: file_url, type: mime_type } ]}
                playing={videoplayer.playing}
                playsinline={true}
                onPlay={this.onPlay.bind( this )}
                onStart={this.onStart.bind( this )}
                onReady={this.onReady.bind( this )}
                onEnded={this.onEnded.bind( this )}
                volume={videoplayer.volume}
                muted={videoplayer.mute}
                loop={false}
                controls={false}
                width='100%'
                height='100%'
                id='video'
                style={{ visibility: 'hidden' }}
                progressFrequency={100}
                onProgress={this.pulse.bind( this )}
            />
@iambumblehead
Copy link
Author

iambumblehead commented Nov 15, 2017

A solution I found was to define the url object above in this way...

url={[ { src: file_url || 1, type: mime_type } ]}

the lifecycle of my application renders video before the file_url is defined

perhaps a change that filters out invalid source definitions or or maybe uses an alternative key when src is undefined?

this.renderSource

return _react2['default'].createElement('source', { key: src, src: src, type: type });

@cookpete
Copy link
Owner

If file_url may not be defined yet I guess the best way to do it would be

url={file_url ? [{ src: file_url, type: mime_type }] : null}

but you're right, the key should fallback to the array index if src is not defined, to avoid errors.

david-hub024 pushed a commit to david-hub024/React_VideoPlayer that referenced this issue Dec 23, 2018
david-hub024 pushed a commit to david-hub024/React_VideoPlayer that referenced this issue May 23, 2020
albanqoku added a commit to albanqoku/react-player that referenced this issue Feb 24, 2021
Webmaster1116 added a commit to Webmaster1116/video-player that referenced this issue May 20, 2021
webmiraclepro added a commit to webmiraclepro/video-player that referenced this issue Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants