亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

React - 元素類型無效:預期是字符串或類/函數,但得到:對象

React - 元素類型無效:預期是字符串或類/函數,但得到:對象

收到一只叮咚 2022-01-01 20:35:48
我正在我的應用程序中實現react-items-carousel。我試圖在我的應用程序中配置一個演示示例。這是演示代碼import React from 'react';import range from 'lodash/range';import styled from 'styled-components';import ItemsCarousel from 'react-items-carousel;const noOfItems = 12;const noOfCards = 3;const autoPlayDelay = 2000;const chevronWidth = 40;const Wrapper = styled.div`  padding: 0 ${chevronWidth}px;  max-width: 1000px;  margin: 0 auto;`;const SlideItem = styled.div`  height: 200px;  background: #EEE;  display: flex;  align-items: center;  justify-content: center;  font-size: 20px;  font-weight: bold;`;const carouselItems = range(noOfItems).map(index => (  <SlideItem key={index}>    {index+1}  </SlideItem>));export default class App extends React.Component {  state = {    activeItemIndex: 0,  };  componentDidMount() {    this.interval = setInterval(this.tick, autoPlayDelay);  }  componentWillUnmount() {    clearInterval(this.interval);  }  tick = () => this.setState(prevState => ({    activeItemIndex: (prevState.activeItemIndex + 1) % (noOfItems-noOfCards + 1),  }));  onChange = value => this.setState({ activeItemIndex: value });  render() {    return (      <Wrapper>        <ItemsCarousel          gutter={12}          numberOfCards={noOfCards}          activeItemIndex={this.state.activeItemIndex}          requestToChangeActive={this.onChange}          rightChevron={<button>{'>'}</button>}          leftChevron={<button>{'<'}</button>}          chevronWidth={chevronWidth}          outsideChevron          children={carouselItems}        />      </Wrapper>    );  }}唯一不同的是我變了import ItemsCarousel from '../../src/ItemsCarousel';到import ItemsCarousel from 'react-items-carousel';我已經調用了組件App而不是AutoPlayCarousel目前在終端應用程序編譯成功但在瀏覽器中我看到以下錯誤元素類型無效:應為字符串(對于內置組件)或類/函數(對于復合組件)但得到:對象。檢查 的渲染方法App。我在許多線程中看到此錯誤的原因可能多種多樣,您能找出我的問題以及我做錯了什么嗎?
查看完整描述

2 回答

?
滄海一幻覺

TA貢獻1824條經驗 獲得超5個贊

我不得不更新到 "react-dom": "^16.3.0"


查看完整回答
反對 回復 2022-01-01
?
拉莫斯之舞

TA貢獻1820條經驗 獲得超10個贊

嘗試提供carouselItemsas 子元素


<Wrapper>

  <ItemsCarousel

    gutter={12}

    numberOfCards={noOfCards}

    activeItemIndex={this.state.activeItemIndex}

    requestToChangeActive={this.onChange}

    rightChevron={<button>{'>'}</button>}

    leftChevron={<button>{'<'}</button>}

    chevronWidth={chevronWidth}

    outsideChevron>


    {carouselItems}


  </ItemsCarousel>

</Wrapper>


查看完整回答
反對 回復 2022-01-01
  • 2 回答
  • 0 關注
  • 260 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號