Node.js is required for this.
npx create-react-app my-app
cd my-app
npm install axios
npm install react-router-dom
Backend needs flask_cors
in order to serve data to another site.
Since this React app has a different protocol / hostname / port combination than the backend,
an error will be thrown by the browser unless the backend has a certain header in its responses.
$ pip install -U flask-cors
from flask import Flask
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
@app.route("/")
def helloWorld():
return "Hello, cross-origin-world!"
Rather than creating different files for different pages, React is used for single-page web apps. They have the functionality of multiple pages, but routing is done in the browser rather than on the server.
React's component structure allows modularity - rather than having to write out a navbar in multiple pages, we can write one and import it where needed.
Use axios to send a GET request. Render the response in the browser.
Use axios to send a POST request.