Skip to content

Instantly share code, notes, and snippets.

@josephan
Last active October 29, 2018 01:31
Show Gist options
  • Save josephan/ddee473ec1f24d77540098631a45a4ec to your computer and use it in GitHub Desktop.
Save josephan/ddee473ec1f24d77540098631a45a4ec to your computer and use it in GitHub Desktop.
How To Add React To Phoenix 1.4

1. cd into assets/ and install the following NPM packages:

npm i react react-dom -S
npm i @babel/preset-react -D

2. add the following line to assets/.babelrc file:

{
    "presets": [
        "@babel/preset-env",
        "@babel/preset-react" // <--- this line
    ]
}

3. test changes:

edit lib/app_web/templates/page/index.html

<div id="root">
</div>

edit assets/js/app.js

import React from "react";
import ReactDOM from "react-dom";

const Index = () => {
  return <div>Hello React!</div>;
};

ReactDOM.render(<Index />, document.getElementById("root"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment