什么是“同构反应"?吝啬的? [英] What does "isomorphic React" mean?

查看:56
本文介绍了什么是“同构反应"?吝啬的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 React 教程,并且在网络上我看到了很多关于同构 React 的内容.只是对它是什么以及它是如何工作的感到困惑.

I was going through React tutorials and on the web I saw a lot about isomorphic React. Just got confused on what it is and how it works.

我的理解是isomorphic React"是一个应用程序,它在启动时加载所有需要的数据,然后根据用户的请求在客户端不断渲染,将完整的数据保存在存储中(Redux架构).

My understanding is that "isomorphic React" is an application is that it loads all the data required at start-up and then it keeps rendering on the client side as per user's request, holding the complete data in store (Redux architecture).

现在,如果我有一个场景,比如我需要使用来自 3rd 方应用程序的 webservice 加载我的完整 HTML 表单,我从中获取数据作为 json(需要在screen) 并在执行某些操作后,我需要将请求发回,以便我将获得一些其他架构以将其加载为我的下一个屏幕.

Now what if I have a scenario like I need to load my complete HTML form using webservice from a 3rd party application where I get the data from it as a json (schema of what fields need to be rendered on the screen) and upon performing some action I need to send the request back so that I will get some other schema to load it as my next screen.

在这种情况下,我如何使用同构,因为每次我需要进行服务器调用或 ajax 调用(我不喜欢这样做,因为它可能会暴露 API).

In this scenario how do I use isomorphic, as every time I need to make a server call or an ajax call (which I do not like to do as it might expose the APIs).

那么在这种情况下,我可以说这个应用程序是同构的还是我对同构的理解完全错误?

So in this case can I say this application as isomorphic or my understanding with regard to isomorphic is completely wrong?

推荐答案

同构:在形式或关系上对应或相似".

Isomorphic: "corresponding or similar in form or relations".

对于网络应用程序,这意味着服务器在某种程度上类似于客户端 - 从某种意义上说,服务器能够像客户端一样渲染.在某种程度上,同构 Web 应用程序是对旧范式的回归,在这种范式中,服务器将呈现数据,然后将其预先呈现给客户端(想想 PHP 模板或 Ruby erb).

With regard to web apps, this means that the server is somehow similar to the client - in the sense that the server is capable of rendering as much as the client. In a way, isomorphic web apps are a return to the old paradigm where the server would render data and then send it pre-rendered to the client (think PHP templates or Ruby erb).

特别是对于同构 React,这意味着服务器使用 React 组件和 React.renderToString() 为客户端呈现初始 HTML.这消除了双重工作,例如在使用 Rails 时在服务器端使用 erb 模板,然后将 Handlebars 用于客户端模板,并且还避免了 FOUC.你可以用 React 做任何事情.

Specifically with isomorphic React, this means that the server renders the initial HTML for the client using React components and React.renderToString(). This eliminates double work such as having erb templates on the server side when using Rails but then using Handlebars for client-side templates and also avoid the FOUC. You can just use React for everything.

现在,如果您使用的是 3rd 方服务,您只需像往常一样使用 json 数据.使您的应用程序同构与否取决于您自己的服务器是否使用与前端相同的模板引擎.您可能使用的任何第三方服务与您的应用程序是否同构无关.

Now, if you're using a 3rd party service, you'd just use the json data as usual. What would make your app isomorphic or not would be whether your own server uses the same templating engine as your front-end. Any third party services you might consume have no bearing on whether your app is isomorphic or not.

这篇关于什么是“同构反应"?吝啬的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆