How to use Thymeleaf th:text in reactJS

后端 未结 3 678
再見小時候
再見小時候 2021-02-07 10:41

I am running a springboot application with Thymeleaf and reactJS. All the HTML text are read from message.properties by using th:text in the pages, but when I have th:text in re

3条回答
  •  鱼传尺愫
    2021-02-07 10:55

    It is possible wrap ReactJS apps in Thymeleaf. Think if you want a static persistent part (like some links, or even just displayed data), you could use Thymeleaf. If you have a complicated part (something that requires DOM repaints, shared data, updates from UI/Sockets/whatever), you could use React.

    If you need to pass state you could use Redux/other methods.

    You could have your backend send data via a rest API to the React part and just render your simple parts as fragments or as whole chunks of plain HTML using Thymeleaf.

    Remember, Thymeleaf is really just HTML. React is virtual DOM that renders as HTML. It's actually fairly easy to migrate one to the other. So you could write anything "Static" or that does not respond much to UI, in Thymeleaf/HTML. You could also just render those parts in React too, but without State.

    Thymeleaf 3 allows you to render variables from your Java to a separate JS file. So that is also an option to pass into JSX

    function showCode() { var code = /*[[${code}]]*/ '12345'; document.getElementById('code').innerHTML = code; }

提交回复
热议问题