I am building this simple react application, I encountered this error which I tried to debug but no joy yet. I am sure I must have been missing something important which may be quite obvious.
*Error: VideoDetail.render(): A valid ReactComponent must be returned. You may have returned undefined, an array or some other invalid object.*
index.js
import React, {
Component
} from 'react';
import ReactDOM from 'react-dom';
import YTSearch from 'youtube-api-search';
import VideoDetail from './components/video_details';
const API_KEY = 'XXXXXXXXXXXXXXXXXXXXXXX';
class App extends Component {
constructor(props) {
super(props);
this.state = {
videos: []
};
YTSearch({
key: API_KEY,
term: 'cute cats'
}, (videos) => {
this.setState({
videos
});
});
}
render() {
return (
<div >
<VideoDetail video = {this.state.videos[0]}/>
</div>
);
}
}
ReactDOM.render( < App / > , document.querySelector('.container'));
video_details.js
import React from 'react';
const VideoDetail = ({ video }) => {
if (!video) {
return (
<div>
Loading...
</div>
);
}
const videoId = video.id.videoId;
const url = `https://www.youtube.com/embed/${videoId}`;
return
(
<div className='video-details col-md-8'>
<div className='embed-responsive embed-responsive-16by9'>
<iframe className='embed-responsive-item' src={url}> </iframe>
<div className='details'>
<div> {video.snippet.title} </div>
<div> {video.snippet.description} </div>
</div>
</div>
</div>
);
}
module.exports = VideoDetail;
I must have been missing something that causes this error. What am I missing?
module.exports = VideoDetail
tryexport default VideoDetail;
– Andy