souporserious / react-media-player

React audio and video player.

Home Page:https://souporserious.github.io/react-media-player/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

<Media> with React.Children.only

dispix opened this issue · comments

Considering this code:

  <Media>
      <Player src={props.src} />
      <Controls />
  </Media>

The console outputs this error:

uncaught at makeAuthenticatedRequest Invariant Violation: React.Children.only expected to receive a single React element child.

Wrapping the children in a div fixes this, but is there a reason for using Children.only in the Media component ?

With the release of React 16 today I think we will be able to just return an array :) I'll try and get to this update as soon as possible.

Is this issue fixed now? I also found this error .

It is not. Do you know if it still errors when returning a Fragment? Please feel free to make a PR with the fix. I'll try and get one out ASAP.

I'm experience problems when returning a Fragment, please see below.

render(){
    const { select } = this.props
    const { PlayPause, CurrentTime, Progress, Duration, MuteUnmute } = controls
    const { artists, titles, energies, genres, popularities, images, previews } = this.state;

    return (
      <>
        { 
          artists.map((artist, index) => {
            /* 
            Obtain preview from state.previews for current artist index 
            */
            const title = titles[index];
            const energy = energies[index];
            const genre = genres[index];
            const popularity = popularities[index];
            const image = images[index];
            const preview = previews[index];
            /* 
            Render current artist data, and corresponding preview data
            for the current artist 
            */
            return (
              <div>
               <h1 className="title is-1"><font color="#C86428">{ this.Capitalize(select) } playlist</font></h1>
                <hr/><br/>
                    <span key={index}>
                      <tr> 
                        <img src={image}  alt="" height="42" width="42" />
                        <td class="number">{ artist }</td>
                        <td class="number">{ title }</td>
                          <Media>
                            <div className="media">
                              <div className="media-player">
                                <Player src={preview} />
                              </div>
                              <div className="media-controls">
                                <PlayPause />
                                <CurrentTime />
                                <Progress />
                                <Duration />
                                <MuteUnmute />
                              </div>
                            </div>
                          </Media>
                      </tr>
                    </span>
              </div>
            )
          })
        }
      </>   
    )
  }

this is the compiling error (sometimes appear sometimes does not):

Module not found: Can't resolve 'react-media-player' in '/usr/src/app/src/components


and here my console.

react-media-player.js:344 Uncaught TypeError: Cannot read property 'Component' of undefined
    at Object.<anonymous> (react-media-player.js:344)
    at __webpack_require__ (react-media-player.js:35)
    at Object.<anonymous> (react-media-player.js:69)
    at __webpack_require__ (react-media-player.js:35)
    at react-media-player.js:55
    at react-media-player.js:58
    at webpackUniversalModuleDefinition (react-media-player.js:14)
    at react-media-player.js:15
(anonymous) @ react-media-player.js:344
__webpack_require__ @ react-media-player.js:35
(anonymous) @ react-media-player.js:69
__webpack_require__ @ react-media-player.js:35
(anonymous) @ react-media-player.js:55
(anonymous) @ react-media-player.js:58
webpackUniversalModuleDefinition @ react-media-player.js:14
(anonymous) @ react-media-player.js:15
20:56:32.522 Brewing.jsx:21 Uncaught Error: Cannot find module 'react-media-player'
    at webpackMissingModule (Brewing.jsx:21)
    at Module../src/components/Coffees.jsx (Brewing.jsx:21)
    at __webpack_require__ (bootstrap:781)
    at fn (bootstrap:149)
    at Module../src/App.jsx (Spotify.css:4)
    at __webpack_require__ (bootstrap:781)
    at fn (bootstrap:149)
    at Module../src/index.js (spotify-auth.js:8)
    at __webpack_require__ (bootstrap:781)
    at fn (bootstrap:149)
    at Object.0 (index.js:10)
    at __webpack_require__ (bootstrap:781)
    at checkDeferredModules (bootstrap:45)
    at Array.webpackJsonpCallback [as push] (bootstrap:32)
    at main.chunk.js:1
webpackMissingModule @ Brewing.jsx:21
./src/components/Coffees.jsx @ Brewing.jsx:21
__webpack_require__ @ bootstrap:781
fn @ bootstrap:149
./src/App.jsx @ Spotify.css:4
__webpack_require__ @ bootstrap:781
fn @ bootstrap:149
./src/index.js @ spotify-auth.js:8
__webpack_require__ @ bootstrap:781
fn @ bootstrap:149
0 @ index.js:10
__webpack_require__ @ bootstrap:781
checkDeferredModules @ bootstrap:45
webpackJsonpCallback @ bootstrap:32
(anonymous) @ main.chunk.js:1
20:56:32.866 
```

what is wrong?