0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.