Franva
Franva

Reputation: 7077

Reactjs Warning: Unknown props `onExited`, `appear`, `enter`, `exit` on <li> tag

I'm following Wes Bos's Reactjs video. In his 22nd video, he is teaching how to use CSSTransitionGroup to do animation.

I found it's deprecated so I installed the latest lib:

react-transition-group

.

I found the CSSTransitionGroup is deprecated so I installed the new react-transition-group and I found that the replacement: TransitionGroup for CSSTransitionGroup.

Here is his code:

              <CSSTransitionGroup
                  className="order"
                  component="ul"
                  transtionName="order"
                  transitionEnterTimeout={500}
                  transitionLeaveTimeout={500}
                  >
                  {orderIds.map(this.renderOrder)}
                  <li className="total">
                      <strong>Total:</strong>{formatPrice(total)}
                  </li>
              </CSSTransitionGroup> 

Here is my code with the new lib:

     <TransitionGroup
                className="order"
                component="ul">
            {/* <ul className="order"> */}
                {orderIds.map(this.renderOrder)}
                <li className="total">
                    <strong>Total:</strong>{formatPrice(total)}
                </li>
                {/* </ul> */}
             </TransitionGroup> 

The UI still renders but it throws me an error and order is not removed after I click the X button. Here is the Error messge:

    Warning: Unknown props `onExited`, `appear`, `enter`, `exit` on <li> tag. Remove these props from the element. For details, see https://facebook.github.io/react/warnings/unknown-prop.html
    in li (at Order.js:24)
    in ul (created by TransitionGroup)
    in TransitionGroup (at Order.js:56)
    in div (at Order.js:53)
    in Order (at App.js:106)
    in div (at App.js:95)
    in App (created by Route)
    in Route (at index.js:20)
    in div (at index.js:18)
    in Router (created by BrowserRouter)
    in BrowserRouter (at index.js:17)
    in Root (at index.js:28)

and here is the code for line 24 in Order.js:

   if (unAvailable) {
            return (
                <li key={key}>Sorry, {fish ? fish.name : 'fish'} is no londer available~! {removeButton}</li>
            );
        }

Upvotes: 3

Views: 3814

Answers (1)

nywooz
nywooz

Reputation: 349

@Franva, I fixed the issue. This error is cause due to the renderOrder component is not the direct children of the Transition group. You will have to declare total as a variable and use it outside TransitionGroup. The below code is not executable due to enormous dependency and setup, but hopefully will help you understand.

 const totalEl = (
      <ul className="order">
        <li className="total">
          <strong>Total:</strong>
          {formatPrice(total)}
        </li>
      </ul>
    );

    return (
      <div className="order-wrap">
        <h2>Order</h2>

        <TransitionGroup className="order" component="ul">
          {orderIds.map(this.renderOrder)}
        </TransitionGroup>

        {totalEl}
      </div>
    );
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

Upvotes: 3

Related Questions