Moving React classes into separate files

后端 未结 3 1941
庸人自扰
庸人自扰 2021-01-31 03:48

After doing the React tutorial this is my index.html file:




  
    

        
3条回答
  •  醉话见心
    2021-01-31 04:12

    In a project created with the create-react-app tool separating components seems to work fine like this. Define the component in a file Hello.jsx:

    import React from 'react';
    
    var Hello = React.createClass({
      render: function() {
        return (
          

    Hello world!

    ); } }); // Must export! export default Hello;

    And then you can import the component in another file with

    import Hello from './Hello.jsx'
    

提交回复
热议问题