Saber2pr's Blog

AboutFrontEndReusability

After writing too many front-end projects, you will find that it is logic that can be reused, and it is almost impossible to reuse the interface and css (unless the product and UI are also copied and pasted), so when writing code, try to separate the logic and the interface, for example, logic is all abstracted into a hook, and the function components are hook calls and jsx structures. The most valuable reuse value of the front end is the customization of the framework, for example, encapsulating the interface request function, token forwarding (cookie or auth, etc.), and designing the directory structure, it is best to extract the common configuration into a configuration file. In this way, when writing a new project, the logic of the request layer can directly change the configuration file reuse. Ideally, when a new project starts, you only need to change the configuration of the framework, and then directly draw the page and interface.