2

Here is an error message:

React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.

The error is pointing to this code line:

 <CSSTransitionGroup {...fadeAnimation}> 

The complete Code:

import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import { CSSTransitionGroup } from 'react-transition-group';

const URL_TEAMS = "http://localhost:3001/teams";

const fadeAnimation = {
  transitionName:"fade",
  transitionAppear:true,
  transitionAppearTimeout:500,
  transitionEnter:true,
  transitionEnterTimeout:500,
  transitionLeave:true,
  transitionLeaveTimeout:500
}

class Teams extends Component {
    constructor(props){
    super(props);

    this.state = {
        teams:[],
        filtered:[],
        keyword:''
    }
}

componentDidMount(){
  fetch(URL_TEAMS,{method: 'GET'})
  .then(response => response.json())
  .then(json => {
    this.setState({
      teams:json,
      filtered:json
    })
  })
}

rendeList = ({filtered}) =>{
  return filtered.map((item) => {
    return(
      <Link to={`/team/${item.name}`} key={item.id} 
      className="team_item">
        <img alt={item.name} src={`/images/teams/${item.logo}`}/>
      </Link> 
    ) 
  })
}

render() {
    return (
        <div className="teams_component">
          <div className="teams_input">
            <input type="text"
                   placeholder="Search for a team"
            />
          </div>
          <div className="teams_container">
             <CSSTransitionGroup {...fadeAnimation}>
               {this.rendeList(this.state)}              
             </CSSTransitionGroup>
           </div>
        </div>
    );
  }
}

export default Teams;
2
  • Just a side question. Why are you passing this.state as a parameter to your method? Commented Sep 15, 2017 at 20:57
  • It is an exercise from a course that taught me how to do it this way and I'm a beginer with this tecnology so I don't know about the reason why the instructor did this way and I don't know which solucion is better. Commented Sep 15, 2017 at 21:47

1 Answer 1

3

According to react-transition-group migration guide:

A few notes to help with migrating from v1 to v2.

The <CSSTransitionGroup> component has been removed. A <CSSTransition> component has been added for use with the new <TransitionGroup> component to accomplish the same tasks.

This tells us that below line is incorrect:

import { CSSTransitionGroup } from 'react-transition-group';

You should use new components like below:

import CSSTransition from 'react-transition-group/CSSTransition';
import TransitionGroup from 'react-transition-group/TransitionGroup';

For more info you can check the docs for react-transition-group.

Sign up to request clarification or add additional context in comments.

1 Comment

the latest for v1.x is import { CSSTransitionGroup } from 'react-transition-group' (src)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.