0

I am working with a player. I'm developing a website in React and want to use Fragment of a video player to use on some pages. So I create videoFr.js script with that code.

import React from 'react'
import '../styles/video.scss';

const fragmentPlayer =(props)=> {
    return (

      <>
      <iframe 
      width="560" 
      height="315" 
      src={props.url} 
      frameborder="0" 
      allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" 
      allowfullscreen>

      </iframe>
      </>
    )


}

export default fragmentPlayer;

I want to render on Main page a video and pass the component.

import React from 'react'
import '../styles/Main.scss';
import fragmentPlayer from '../Components/video.js';

class Main extends React.Component {



    render(){
        return (
           <body>
               <sector id='banner'>
                   <h1>hi {this.props.name}</h1>
                <h1>- Culture</h1>
                <p>We unite business and education. And much more...</p>
                <fragmentPlayer url="https://www.youtube.com/embed/QTACugN67yc"/>
               </sector>
               <sector id='m-training'>
               <h1>TRAINING & COMPETITION</h1>
                <p>Every semester, thousands participants  from over 90 countries join the X-Culture competition.
                <br/>They compete, collaborate, learn the challenges and best practices of international business consulting.</p>
               </sector>
               <sector id='m-business'>
               <h1>BUSINESS SOLUTIONS</h1>
                <p>Companies present their business challenges. Thousands of amateurs and professionals develop their solutions.
                    <br/>If there is something good for your business out there, they will find it and bring it to you.</p>
               </sector>
           </body>

        )

    }
}

export default Main;

Nothing happens in render. However, when I import not fragmentPlayer from my script, but Player and use Player - everything works fine.

import Player from '../Components/video.js';
 <Player url="https://www.youtube.com/embed/QTACugN67yc"/>

What's going on here?

4

1 回答 1

1

在 React 中,我们的组件名称的第一个字母必须大写,因为这就是 React 我们的组件和 html 标签之间的区别。所以使用

import FragmentPlayer from '../Components/video.js';

代替

import fragmentPlayer from '../Components/video.js';
于 2020-03-14T08:31:37.343 回答