I am new to React and trying to debug the following errors I am seeing.
Error #1:
Uncaught TypeError: props.videos.map is not a function
at new VideoList
Error #2:
bundle.js:19956 Error: findComponentRoot(..., .0.0.0): Unable to find element.
This probably means the DOM was unexpectedly mutated (e.g., by the browser),
usually due to forgetting a <tbody> when using tables, nesting tags like
<form>, <p>, or <a>, or using non-SVG elements in an <svg> parent.
Try inspecting the child nodes of the element with React ID ``.
Here is my code in reference to this file:
import React from 'react';
import VideoListItem from './video_list_item';
const VideoList = (props) => {
const videoItems = props.videos.map((video) => {
return <VideoListItem key={video.etag} video={video} />
});
return (
<ul className ="col-md-4 list-group">
{videoItems}
</ul>
);
};
export default VideoList;
Index.js file:
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import YTSearch from 'youtube-api-search';
import SearchBar from './components/search_bar';
import VideoList from './components/video_list'
const API_KEY = '';
// create a new component. This component should produce
// some HTML
class App extends Component {
constructor(props) {
super(props);
this.state = { videos: {} };
YTSearch({key: API_KEY, term: 'React'}, (videos) => {
this.setState({ videos });
});
}
render() {
return (
<div>
<SearchBar />
<VideoList videos={this.state.videos} />
</div>
);
}
}
// Take this component's generated HTML and put it
// on the page (in the DOM)
ReactDOM.render(<App />, document.querySelector('.container'));
I reviewed the following questions on SOF but neither could resolve my issue:
React JS - Uncaught TypeError: this.props.data.map is not a function
React.js this.props.data.map() is not a function
What I am having a hard time understanding is why it's giving me error #1 because I am using the function declaration with the 'fat arrows'. And I assume Error #2 is a result of Error #1.
What am I doing wrong?