Answer the question
In order to leave comments, you need to log in
Why is the component unknown?
App:
export const App = () => {
const [layout, handleChangeLayout] = useState(LayoutType.DESKTOP);
return (
<React.Fragment>
<Header>
{PAGE_TITLE}
</Header>
<SwitchLayout
layout={layout}
onChangeLayout={handleChangeLayout}
/>
<MovieList
layout={layout}
/>
</React.Fragment>
);
};
export const MovieList = connect(
createStructuredSelector({
movies: getMoviesSelector,
recommendations: getRecommendationsSelector,
}),
{ getData: requestData },
)(({
movies,
recommendations,
layout,
getData,
} : MovieListPropsType) => {
useEffect(() => {
getData();
}, []);
return (
<div className="container">
<div className="row">
{movies && movies.map((movie, index) => (
<Movie
key={movie.id}
even={(index + 1) % 2 === 0}
layout={layout}
movie={movie}
recommendation={find(recommendations, { movieId: movie.id })}
/>
))}
</div>
</div>
);
});
Answer the question
In order to leave comments, you need to log in
The essence of the problem is that the anonymous function has an empty name property.
React uses either the given displayName property or the function's own name property. None of the properties are found and you see Unknown
connect in turn, if when creating a wrapper it does not find one of these properties, it uses the word Component , which you see in brackets.
In a good way, the components are described as follows:
const MovieList: React.FC<MovieListPropsType> = ({ ... }) => { ... };
const mapStateToProps = createStructuredSelector({ ... });
const mapDispatchToProps = { ... };
export default connect(mapStateToProps, mapDispatchToProps)(MovieList);
const MovieList = ...
MovieList.displayName = 'MovieList';
export MovieList;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question