Reputation: 4253
I'm new using reactjs. I'm building a multipage website that I'd like to use react and I was wondering what is the best practise...
I'm adding react like I used to add jquery in my pages:
...
<script src="https://unpkg.com/react@16/umd/react.production.min.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js" crossorigin></script>
<script src="https://unpkg.com/axios/dist/axios.min.js" crossorigin></script>
<!-- Load React component. -->
<script src="my_index_page_react.js"></script>
</body>
</html>
For each page (index.php, login.php, feed.php...) I add a react.js that I created. (login_react.js, feed_react.js...)
I know I can use instead the npm with node and build it:
create-react-app my_app
Is there any problem using react as I'm using, adding the libraries manually and creating in each page a JS with that page react code or is it ok?
Thanks.
Upvotes: 0
Views: 51
Reputation: 1293
Although this is possible and I've even seen this done in production, I very strongly advise against it.
React was designed to be used for single-page applications. It is very difficult to manage state between separate React instances across your multi-page app. I've never seen any benefit in doing this other than to gradually move away from a multi-page app to a single-page app.
Upvotes: 1