L
L
lexstile2019-08-01 15:28:37
React
lexstile, 2019-08-01 15:28:37

Why is the component unknown?

5d42df4384e65491911963.png
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>
  );
};

movielist:
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>
  );
});

Why is the wrapper component unknown? (So ​​it should be, or am I missing something somewhere? What exactly?)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Spirin, 2019-08-01
@lexstile

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);

PS you have a mistake in the word Desktop .

A
Alexey Ukolov, 2019-08-01
@alexey-m-ukolov

const MovieList = ...

MovieList.displayName = 'MovieList';

export MovieList;

D
Dmitry, 2017-11-30
@salarimus

Try this.

switch (action.type){
        case 'ADD_PRODUCT':
            return {...state,  isAdded: action.payload};
        default:
            return state;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question