Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[React] 高阶组件 #136

Open
plh97 opened this issue Mar 8, 2019 · 0 comments
Open

[React] 高阶组件 #136

plh97 opened this issue Mar 8, 2019 · 0 comments
Assignees
Labels
react react项目

Comments

@plh97
Copy link
Owner

plh97 commented Mar 8, 2019

前言

很久没写文章了,这一次打算学习并介绍一次高阶组件

background

react 单页面应用,我需要在react-router-dom切换路由的时候,自动切换页面的title.希望能实现利用@autoTitle装饰器来实现这个功能.算是学习 react 第一步吧....

AutoTitle 的高阶组件

import React, { Component } from 'react';
const AutoTitle = title => (WrappedComponent) => class extends Component {
    constructor(){
        super()
        document.title = title
        super.componentDidMount && super.componentDidMount()
    }
    render(h) {
        return <WrappedComponent {...this.props}/>
    }
}
export default AutoTitle;
@plh97 plh97 self-assigned this Mar 8, 2019
@plh97 plh97 added the react react项目 label Mar 8, 2019
@plh97 plh97 changed the title Reactjs 高阶组件 [React] 高阶组件 Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
react react项目
Projects
None yet
Development

No branches or pull requests

1 participant