bsky
bsky

Reputation: 20222

Setting up React classes to be compiled in Play

In my Play project, I added a simple React class to /app/assets/js:

var Question = React.createClass({

  render: function() {
    return (<div>
      <p>{this.props.content}</p>
      <br>
      <p>{this.props.answer}</p>
    </div>);
  }
});

And I added the following to build.sbt:

libraryDependencies += "org.webjars" % "react" % "0.14.7"

However, the JSX notation is still not recognised.

What else do I need to do to be able to use React in my Play project?

Upvotes: 1

Views: 325

Answers (1)

bjfletcher
bjfletcher

Reputation: 11518

There is a full and working Play 2.4 and React 0.14 sample project by @ticofab here:

https://github.com/ticofab/play-scala-webjars-react

along with a blog post detailing all the steps needed:

http://ticofab.io/react-js-tutorial-with-play_scala_webjars/

which explains how to compile it all server-side using sbt-reactjs as you discussed with @Odomontois in the comments.

Upvotes: 1

Related Questions