gpt4 book ai didi

javascript - 目标容器不是 DOM 元素 - React 和 GatsbyJS - React-slick Component

转载 作者:行者123 更新时间:2023-12-03 02:18:56 25 4
gpt4 key购买 nike

我正在尝试使用 React-Slick轮播组件,但在将其显示在应用程序中时遇到问题并收到此错误...

Uncaught (in promise) Error: _registerComponent(...): Target container is not a DOM element.

featuresCarousel.js

import React from "react";
import ReactDOM from "react-dom";
import { render } from "react-dom";
import Slider from 'react-slick';


class featuresCarousel extends React.Component{
render() {
const settings = {
autoplay: true
}
return (
<div className='container'>
<Slider {...settings}>
<div>Test</div>
<div>Test2</div>
<div>Test3</div>
</Slider>
</div>
);
}
};

ReactDOM.render(
<featuresCarousel />,
document.getElementById('container')
);

应该显示在页面部分3-section.js中,然后显示在页面中。

import React from 'react'
import featuresCarousel from '../home/featuresCarousel'

const SectionThree = (props) => (
<div>
<featuresCarousel />
</div>
)

export default SectionThree

不确定它是否会有所作为,但我也在使用 GatsbyJS GatsbyJs 和我对 React 的了解有限而且非常新。

最佳答案

您的组件名称 featuresCarousel 应采用大写 FeaturesCarousel

class FeaturesCarousel extends React.Component{
render() {
const settings = {
autoplay: true
}
return (
<div className='container'>
<Slider {...settings}>
<div>Test</div>
<div>Test2</div>
<div>Test3</div>
</Slider>
</div>
);
}
};

const SectionThree = (props) => (
<div className="SectionThree">
<FeaturesCarousel />
</div>
)

export default SectionThree

ReactDOM.render(
<SectionThree />,
document.getElementById('root')
);

Working Demo

关于javascript - 目标容器不是 DOM 元素 - React 和 GatsbyJS - React-slick Component,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49248932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com