


Detailed explanation of React's use of referencing component instances relative to the root directory
This article mainly introduces to you the relevant information on how to use React to reference components relative to the root directory. The article introduces it in great detail through sample code. It has certain reference learning value for everyone's study or work. Friends who need it Let's learn with the editor below, I hope it can help everyone.
In the components developed by myself, I often make references such as the following:
import genFetchEntryListArgs from '../../../utils/table/genFetchEntryListArgs'; import { parseQuery, stringifyQuery } from '../../../utils/query'; import mapMyToProps from '../../../utils/connect/mapMyToProps'; import genPagination from '../../../utils/table/pagination'; import handleConfirm from '../../../utils/handleConfirm'; import getBaseQuery from '../../../utils/getBaseQuery'; import setSortQuery from '../../../utils/setSortQuery'; import handleError from '../../../utils/handleError'; import injectProto from '../../../utils/injectProto'; import injectApi from '../../../utils/injectApi'; import querySchema from './querySchema'; import genColumns from './genColumns';
Although using relative path references in this way is It is a relatively common approach, but in medium and large projects, when a lot of components are introduced, it is extremely painful to write.
Of course, we can configure certain file directories as fixed imports by using resolve.alias
in webpack to configure aliases.
For example, in the above example, we can set the utils folder as a utils alias. In the future, we can only import utils without writing a bunch of ../../../.
The configuration settings are as follows:
const path = require('path'); module.exports = { ... resolve: { alias: { 'utils': path.resolve(__dirname, '../src/utils'), } }, ... };
After the top example has been rewritten, it should look like this:
import genFetchEntryListArgs from '../../../utils/table/genFetchEntryListArgs'; import { parseQuery, stringifyQuery } from 'utils/query'; import mapMyToProps from 'utils/connect/mapMyToProps'; import genPagination from 'utils/table/pagination'; import handleConfirm from 'utils/handleConfirm'; import getBaseQuery from 'utils/getBaseQuery'; import setSortQuery from 'utils/setSortQuery'; import handleError from 'utils/handleError'; import injectProto from 'utils/injectProto'; import injectApi from 'utils/injectApi'; import querySchema from './querySchema'; import genColumns from './genColumns';
Related recommendations:
php Several methods to obtain the physical path of the website root directory (recommended) Tips
The above is the detailed content of Detailed explanation of React's use of referencing component instances relative to the root directory. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to build a reliable messaging application with React and RabbitMQ Introduction: Modern applications need to support reliable messaging to achieve features such as real-time updates and data synchronization. React is a popular JavaScript library for building user interfaces, while RabbitMQ is a reliable messaging middleware. This article will introduce how to combine React and RabbitMQ to build a reliable messaging application, and provide specific code examples. RabbitMQ overview:

ReactRouter User Guide: How to Implement Front-End Routing Control With the popularity of single-page applications, front-end routing has become an important part that cannot be ignored. As the most popular routing library in the React ecosystem, ReactRouter provides rich functions and easy-to-use APIs, making the implementation of front-end routing very simple and flexible. This article will introduce how to use ReactRouter and provide some specific code examples. To install ReactRouter first, we need

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.

The glob() function in PHP is used to find files or directories and is a powerful file operation function. It can return the path of a file or directory based on a specified pattern match. The syntax of the glob() function is as follows: glob(pattern, flags) where pattern represents the pattern string to be matched, which can be a wildcard expression, such as *.txt (matching files ending with .txt), or a specific file path. flags is an optional parameter used to control the function

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.

Select the style of the catalog in Word, and it will be automatically generated after the operation is completed. Analysis 1. Go to Word on your computer and click to import. 2After entering, click on the file directory. 3 Then select the style of the directory. 4. After the operation is completed, you can see that the file directory is automatically generated. Supplement: The table of contents of the summary/notes article is automatically generated, including first-level headings, second-level headings and third-level headings, usually no more than third-level headings.

The mobile version of WeChat Reading App is a very good reading software. This software provides a lot of books. You can read them anytime, anywhere with just one click to search and read them online. All of them are officially authorized and different types of books are neatly arranged. Sort and enjoy a comfortable and relaxing reading atmosphere. Switch the reading modes of different scenarios, update the latest book chapters continuously every day, support online login from multiple devices, and batch download to the bookshelf. You can read it with or without the Internet, so that everyone can discover more knowledge from it. Now the editor details it online Promote the method of viewing the catalog for WeChat reading partners. 1. Open the book you want to view the catalog and click in the middle of the book. 2. Click the three lines icon in the lower left corner. 3. In the pop-up window, view the book catalog

How to use React to develop a responsive backend management system. With the rapid development of the Internet, more and more companies and organizations need an efficient, flexible, and easy-to-manage backend management system to handle daily operations. As one of the most popular JavaScript libraries currently, React provides a concise, efficient and maintainable way to build user interfaces. This article will introduce how to use React to develop a responsive backend management system and give specific code examples. Create a React project first
