Home Web Front-end JS Tutorial react project case summary

react project case summary

Feb 10, 2018 pm 03:32 PM
react Summarize project

When I first started writing components, it didn’t feel too difficult (similar to vue). The most interesting thing should be jsx syntax. Personally, I feel that jsx is indeed more functional than vue's template, and more readable.

// vue
<p :id="text" :class="{&#39;active&#39;:isActive}" v-text="&#39;hello! &#39; + msg"></p>
Copy after login
// jsx
<p id={text} className={isActive && &#39;active&#39;}>hello !{msg}</p>
Copy after login
  1. There are no instructions in jsx, and {} in jsx represents the js statement to be executed. Its effect is similar to return, and it will have a return value. In this case, it is better to understand the content of jsx. The dom in jsx is not The real dom is just a syntax for expressing dom. The content in {} can be completely understood as js, and the entire jsx can be understood as an html template written in native js.

  2. For the attribute calculation part, you need to add : in front of the attribute name in vue, but not in jsx.

  3. In addition, in The contentText of the dom in vue is not rendered using {{}}, because before the vue page is generated, the template syntax part is not rendered, and it will appear on the page first{{content}}, and then it flashes into the real text content.

Another example of array traversal rendering
// vue
<ul>
  <li v-for="(item,index) in list" :key="index" v-if="showItem(item)">
    <span v-text="item.label"></span>
  </li>
</ul>

// vue的methods属性
methods:{
  showItem(item){
    return item.label.indexOf('abc') !== -1
  }
}
Copy after login
// jsx
<ul>
  {list.map((item,index) => {
    return item.label.indexOf('abc') !== -1 && (
      <li key={index}>
        <span>{item.label}</span>
      </li>
    )
  })}
</ul>
Copy after login

You will I found that when it comes to some relatively simple rendering requirements, using vue's template will be simpler, more direct, and easy to understand. But if it involves some more complex logic processing and rendering, jsx is more intuitive, because the syntax of jsx is not much different from that of js. It is equivalent to using js to describe how to render the dom structure. Of course, jsx does not mean that you can use the syntax of js to write dom. {} can only be an expression, so like if else or switch This syntax cannot be used in {}.

Regarding the formatting of component templates, it feels better in react, because The react component is written in js. The formatting and annotation parts are better supported in the editor, but the .vue file cannot currently find the formatting plug-in for it.
Currently I have encountered There are two problems.

1. The problem of component comments.
When writing components, I am more accustomed to writing comments. In js files, comments will be more obvious and convenient, but in vue The comments in the file feel less friendly.

// .vue
<template>
<!--
  这里是注释,而且没有高亮效果.
 -->
</template>
Copy after login
// .js
/**
 * @name
 * @param {Number}
 * @description
 */
Copy after login

The comments in js will look very high-end.

2. Partial formatting of dom.
Vue recommends that every dom Each attribute occupies one line (also my writing habit), like this:

// .vue
<p
  id="box1"
  class="classA classB"
  :class="{&#39;active&#39;:isActive}"
></p>
Copy after login

However, as soon as it is formatted,...

// .vue
<p id="box1" class="classA classB" :class="{&#39;active&#39;:isActive}"></p>
Copy after login

This does not happen in jsx , as long as the line is changed, the above problem will not occur even if it is formatted.

Related recommendations:

Several advanced methods of decomposing React components

Analysis of new features of React 16.3

Detailed explanation of Context API of React 16.3


The above is the detailed content of react project case summary. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Can AI conquer Fermat's last theorem? Mathematician gave up 5 years of his career to turn 100 pages of proof into code Can AI conquer Fermat's last theorem? Mathematician gave up 5 years of his career to turn 100 pages of proof into code Apr 09, 2024 pm 03:20 PM

Fermat's last theorem, about to be conquered by AI? And the most meaningful part of the whole thing is that Fermat’s Last Theorem, which AI is about to solve, is precisely to prove that AI is useless. Once upon a time, mathematics belonged to the realm of pure human intelligence; now, this territory is being deciphered and trampled by advanced algorithms. Image Fermat's Last Theorem is a "notorious" puzzle that has puzzled mathematicians for centuries. It was proven in 1993, and now mathematicians have a big plan: to recreate the proof using computers. They hope that any logical errors in this version of the proof can be checked by a computer. Project address: https://github.com/riccardobrasca/flt

A closer look at PyCharm: a quick way to delete projects A closer look at PyCharm: a quick way to delete projects Feb 26, 2024 pm 04:21 PM

Title: Learn more about PyCharm: An efficient way to delete projects. In recent years, Python, as a powerful and flexible programming language, has been favored by more and more developers. In the development of Python projects, it is crucial to choose an efficient integrated development environment. As a powerful integrated development environment, PyCharm provides Python developers with many convenient functions and tools, including deleting project directories quickly and efficiently. The following will focus on how to use delete in PyCharm

PHP, Vue and React: How to choose the most suitable front-end framework? PHP, Vue and React: How to choose the most suitable front-end framework? Mar 15, 2024 pm 05:48 PM

PHP, Vue and React: How to choose the most suitable front-end framework? With the continuous development of Internet technology, front-end frameworks play a vital role in Web development. PHP, Vue and React are three representative front-end frameworks, each with its own unique characteristics and advantages. When choosing which front-end framework to use, developers need to make an informed decision based on project needs, team skills, and personal preferences. This article will compare the characteristics and uses of the three front-end frameworks PHP, Vue and React.

Integration of Java framework and front-end React framework Integration of Java framework and front-end React framework Jun 01, 2024 pm 03:16 PM

Integration of Java framework and React framework: Steps: Set up the back-end Java framework. Create project structure. Configure build tools. Create React applications. Write REST API endpoints. Configure the communication mechanism. Practical case (SpringBoot+React): Java code: Define RESTfulAPI controller. React code: Get and display the data returned by the API.

Vue.js vs. React: Project-Specific Considerations Vue.js vs. React: Project-Specific Considerations Apr 09, 2025 am 12:01 AM

Vue.js is suitable for small and medium-sized projects and fast iterations, while React is suitable for large and complex applications. 1) Vue.js is easy to use and is suitable for situations where the team is insufficient or the project scale is small. 2) React has a richer ecosystem and is suitable for projects with high performance and complex functional needs.

The 'trader” behind many popular projects, Bitcoin NFT project NodeMonkes is facing strong gains The 'trader” behind many popular projects, Bitcoin NFT project NodeMonkes is facing strong gains Feb 27, 2024 am 11:58 AM

With the support of many factors such as the team background and the attributes of the golden shovel, the price of NodeMonkes has hit new highs repeatedly and is considered a strong competitor for Bitcoin's NFT leader. So, with so many small pictures competing on the same stage, how did NodeMonkes quickly gather community consensus in the short term and occupy a place in the hot Bitcoin market? "NodeMonkes is not an institution, movement, council or DAO and has no utility, roadmap, events, merchandise, etc., but likes to try and create cool things and enjoy them." As the second person to land at the well-known auction house Sotheby's A Bitcoin project, NodeMonkes is the first original 10KPFP series on Bitcoin, with a total amount of 10,000, created by anonymous member Nodet

React's Role in HTML: Enhancing User Experience React's Role in HTML: Enhancing User Experience Apr 09, 2025 am 12:11 AM

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

Golang Project Revealed: Explore popular projects in Go language Golang Project Revealed: Explore popular projects in Go language Feb 29, 2024 pm 04:09 PM

Golang Project Revealed: Explore Popular Projects of Go Language As an efficient, concise and powerful programming language, Go language has attracted much attention and favor from developers in recent years. Among many projects, there are some well-respected and popular projects that have become the focus of attracting a large number of developers due to their high performance, concurrent processing, concise code and other characteristics. This article will lead readers to explore these excellent Go projects in depth, combining specific code examples to reveal the design ideas and engineering implementations behind them. 1.GinGin is a user-friendly

See all articles