javascript - 转换为类组件?
问题描述
当我将其转换为类组件时,道具正在被定义。所以我们应该如何编写这是类组件
const Admin = props => {
console.log(props);
const username = props.location.username;
return (
<div>
<NavLink to="/" activeClassName="active">
LOGOUT
</NavLink>
<br/>
<br/>
<Button>hello</Button>
<h2> Username </h2> {username}
<h1>child component-MILAN</h1>
</div>
);
解决方案
类组件
import React, { Component } from 'react';
export default class Admin extends Component {
render() {
const username = this.props.location.username;
return (
<div>
<NavLink to="/" activeClassName="active">
LOGOUT
</NavLink>
<br />
<br />
<Button>hello</Button>
<h2> Username </h2> {this.username}
<h1>child component-MILAN</h1>
</div>
);
}
}
推荐阅读
- .net - 如何将 Windows.Automation 程序集添加到我的 .Net 5.0 项目中?
- system-verilog - 在 SystemVerilog 测试台生成器类中——如何生成无限长的数据流
- python - 重新索引数据框
- pandas - 定义一个函数来查看特定列的唯一值
- python - 由于没有匹配的参数类型,函数调用失败。web3.py, Python
- php - 使用 str_ireplace 将 HTML 标记添加到 PHP 数组中的字符串
- java - 很少有 junit 测试在 ant build 运行中失败但在 eclipse 中通过
- python - 在没有 np.concatenate 或 np.append 的情况下将 3D numpy 数组转换为 2D
- ios - 当文件选择器未下载 Google Drive 文件时,为什么 FileManager 无法复制文件?
- windows-installer - 如何在 NSIS 脚本中添加文件选择输入?