0

I was looking over the following tutorial using Spring Boot and React. https://spring.io/guides/tutorials/react-and-spring-data-rest/

Would the React be server-side rendered here, since it is being rendered into the Thymeleaf template? For context I have placed the Thymeleaf template and React file code from the tutorial below.

src/main/resources/templates/index.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta charset="UTF-8"/>
    <title>ReactJS + Spring Data REST</title>
    <link rel="stylesheet" href="/main.css" />
</head>

<body>

    <div id="react"></div>

    <script src="built/bundle.js"></script>

</body>
</html>

src/main/js/app.js - rendering code

ReactDOM.render(
    <App />,
    document.getElementById('react')
)

2 Answers 2

3

In the given example React is not rendered server-side. The Thymeleaf HTML is outputted as is. Data is fetched client-side by calling services setup in the Spring Boot backend as shown in the tutorial.

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

1 Comment

Thanks, I thought this was the likely case but wasn't sure.
0

There's no reason you cannot combine the two. Your example doesn't use any Thymeleaf templating, though, but if you did add it, and make Spring render it, then it would have both client-side ReactJS DOM components post-rendered after Spring's server-side HTML response.

As one example, you could do conditional rendering

<div id="react" th:if="some condition here"></div>
<div id="other-react" th:if="other condition here"></div>

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.