然而,重要的是要记住,教条和虔诚地遵循这些原则可能是有害的,并导致过度设计的代码,因此我们必须学会识别何时分解或解耦组件会引入复杂性或没有好处。 最初发表于https://medium.com/dailyjs/applying-solid-principles-in-react-14905d9c5377 Github [ 纽顿- 概述 软件工程师。 newerton 有
https://betterprogramming.pub/how-to-apply-solid-principles-to-clean-your-code-in-react-cdfd5e0a9cea:
让我们把获取远程数据的逻辑提取到一个单独的钩子,这个钩子的名字是useHttpGetRequest,它把 URL 作为一个参数: import {useEffect, useReducer, useState} from "react"; import {loadingReducer} from "./LoadingReducer"; const initialState = { isLoading: true }; export const useHttpGetRequest = (URL) ...
import React from "react"; import {useGetRemoteData} from "./useGetRemoteData"; export const SingleResponsibilityPrinciple = () => { const {filteredUsers , isLoading} = useGetRemoteData() const showDetails = (userId) => { const user = filteredUsers.find(user => user.id===userId); ...
Amy认为,React hooks 不尊重SOLID架构原则。我不太同意,但我承认,在网上找到的大多数例子都是简化的,不一定能突出一个好的架构。 Applying SOLID principles in React 几乎是对上述文章的直接回答,即使SOLID的应用在这里被更广泛地覆盖(components + hooks)。注意:不要犹豫,使用React上下文进行依赖注入。 拓展阅读 Av...
https://betterprogramming.pub/how-to-apply-solid-principles-to-clean-your-code-in-react-cdfd5e0a9cea:https://betterprogramming.pub/how-to-apply-solid-principles-to-clean-your-code-in-react-cdfd5e0a9cea ———
例如下面的react代码,我们经常看到组件负责太多事情——例如管理UI和业务逻辑。 代码语言:javascript 代码运行次数:0 运行 AI代码解释 functionUserProfile({userId}){const[user,setUser]=useState(null);useEffect(()=>{fetchUserData();},[userId]);asyncfunctionfetchUserData(){constresponse=awaitfetch(`/api/...
In this article, we’ll break down each of the five SOLID principles—Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion—and explore how they naturally fit into React development. By the end, you'll have practical strategies to write cleaner, ...
Principios SOLID aplicados al Frontend con REACT. Documentación basada en https://www.youtube.com/watch?v=jKdt-BnTTR0&ab_channel=midulive Topics react typescript study frontend solid solid-principles midudev Resources Readme License MIT license Activity Stars 4 stars Watchers 3 watching...
本月我们将介绍 TypeScript 中的 SOLID 原则、React 应用程序的软件设计模式、焦点样式和新的单独 CSS 转换属性。 由Whitespectre 工程团队提供 August 2022 Frontend Updates: SOLID Principles in TypeScript, Software Design Patterns, Focus Styles and Individual CSS Transform Properties ...