React 设计模式与最佳实践 个人总结

React 设计模式与最佳实践 个人总结

高阶组件

高阶组件即接受组件返回组件,形式如下:

const HoC=Component=>EnhanceComponent
案例: 对获取数据封装

对数据获取渲染,我们会这么做…

export default class UserList extends Component {
   
    state = {
   
        list: []
    }
    componentDidMount() {
   
        fetch('')
            .then(response => response.json())
            .then(list => this.setState({
    list }))
    }
    render() {
   
        return (
            <>
                <ul>
                    {
   
                        this.state.list.map(user => (
                            <li key={
   user.id}>{
   user['name']}</li>
                        ))
                    }
                </ul>
            </>
        )
    }
}

封装获取数据后,可以让多处代码获取同一个api数据。我们可以这么做…

const widthData: IWidthData = url => Component => {
   
    return class extends React.Component {
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Key Features Dive into the core patterns and components of React.js in order to master your application's design Improve their debugging skills using the DevTools This book is packed with easy-to-follow examples that can be used to create reusable code and extensible designs Book Description Taking a complete journey through the most valuable design patterns in React, this book demonstrates how to apply design patterns and best practices in real-life situations, whether that's for new or already existing projects. It will help you to make your applications more flexible, perform better, and easier to maintain - giving your workflow a huge boost when it comes to speed without reducing quality. We'll begin by understanding the internals of React before gradually moving on to writing clean and maintainable code. We'll build components that are reusable across the application, structure applications, and create forms that actually work. Then we'll style React components and optimize them to make applications faster and more responsive. Finally, we'll write tests effectively and you'll learn how to contribute to React and its ecosystem. By the end of the book, you'll be saved from a lot of trial and error and developmental headaches, and you will be on the road to becoming a React expert. What You Will Learn Write clean and maintainable code Create reusable components applying consolidated techniques Use React effectively in the browser and node Choose the right styling approach according to the needs of the applications Use server-side rendering to make applications load faster Build high-performing applications by optimizing components About the Author Michele Bertoli is a frontend engineer with a passion for beautiful UIs. Born in Italy, he moved to London with his family to look for new and exciting job opportunities. He has a degree in computer science and loves clean and well-tested code. Currently, he is working

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值