Javascript 使用 ReactJS 的优缺点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28442239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:47:38  来源:igfitidea点击:

Advantages and Disadvantages of using ReactJS

performanceopen-sourcereactjsjavascript

提问by XpertSiji

I am new to using React for development.

我是使用 React 进行开发的新手。

Can someone list the advantages and disadvantages in using ReactJS. Are there any performance issues with using this library for large projects.

有人可以列出使用 ReactJS 的优点和缺点吗?将此库用于大型项目是否存在任何性能问题。

采纳答案by Jeremy D

Advantages of using React:

使用 React 的优点:

  • easy to know how a component is rendered, you just look at the render function.
  • JSX makes it easy to read the code of your components. It is also really easy to see the layout, or how components are plugged/combined with each other.
  • you can render React on the server-side.
  • it is easy to test, and you can also integrate some tools like jest.
  • it ensures readability and makes maintainability easier.
  • you can use React with any framework (Backbone.js, Angular.js) as it is only a view layer.
  • 很容易知道一个组件是如何渲染的,你只需要看看渲染函数。
  • JSX 使阅读组件代码变得容易。也很容易看到布局,或者组件是如何相互插入/组合的。
  • 你可以在服务器端渲染 React。
  • 它易于测试,您还可以集成一些工具,例如 jest。
  • 它确保了可读性并使可维护性更容易。
  • 你可以将 React 与任何框架(Backbone.js、Angular.js)一起使用,因为它只是一个视图层。

What is not so good about React?

React 有什么不好的地方?

  • it is only a view layer, you have still to plug your code for Ajax requests, events and so on. Some people get surprised by that.
  • the library itself is pretty large.
  • the learning curve can be steep.
  • 它只是一个视图层,您仍然需要为 Ajax 请求、事件等插入代码。有些人对此感到惊讶。
  • 图书馆本身很大。
  • 学习曲线可能很陡峭。

If react-native is really how it was described, react is going to become even bigger.

如果 react-native 真的如其所描述的那样,react 将会变得更大。

Performance wise, it is really good as it relies on a virtual-dom to know what is really changing in your UI and will re-render only what has really changed. It does have trouble with very large, slightly changing, lists of children (2000 <li>test), but can be optimized simply.

在性能方面,它非常好,因为它依赖于虚拟 dom 来了解 UI 中真正发生的变化,并且只会重新呈现真正发生变化的内容。它在处理非常大的、略有变化的子项列表(2000 年<li>测试)时确实存在问题,但可以简单地进行优化。

If you are not sure, just think about the big projects using React: instagram, hipchat, facebook chat and so on.

如果您不确定,请考虑使用 React 的大项目:instagram、hipchat、facebook chat 等。

Some resources:

一些资源:

And probably one of my favorite blog post Why React is awesome?

可能是我最喜欢的博客文章之一为什么 React 很棒?