简体   繁体   中英

Rails React Component Renders But Not Visible on Page

I just added the react-rails gem to my project and tried to add a react component to my index.html.erb file. I used the react component generator to make a simple message/text element, but it does not show up on my view after I deploy to Heroku, but it seems to render when I inspect the page. I have no idea why this isn't working.

Please look at the images I have attached. It looks like the javascript doesn't get compiled??

Body inspection part 2

index.html.erb code

    <h2>Dashboard</h2>
    <%= react_component('Message', text: 'hello') %>
    <h3>Products TEST REACT </h3>

Message.jsx code

var React = require("react")
class Message extends React.Component {
  render () {
    return (
      <div>
        <div>Text: {this.props.text}</div>
      </div>
    );
  }
}

Message.propTypes = {
  text: React.PropTypes.string
};
module.exports = Message

HTML body inspection

我在安装react-rails之前恢复到git commit并使用了shakacode react-on-rails gem使其工作

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM