import React, { Component } from 'react'
// import LazyComponent from './LazyComponent'
const LazyComponent = React.lazy(() => import('./LazyComponent'))
export default class Layout extends Component {
constructor() {
super()
this.state = {
flag: false
}
clickHandler = () => {
this.setState({
flag: true
})
render() {
return (
<div>
<h3>主组件</h3>
<button onClick = {this.clickHandler}>加载组件</button>
{this.state.flag && <LazyComponent/>}
</div>
)
老师我这里不报错了,是因为react升级新版本后可以这么写了吗?
export default class ChildComponent extends Component {
componentWillUnmount() {
console.log("componentWillUnmount", "组件将要卸载")
<h3>ChildComponent</h3>
为什么我的组件在页面打开时就能调用呢
componentWillUnmount 组件将要卸载但是这个提示是灰色的是执行了吗?
老师,如果key没变, 里边的内容变化了,会重新渲染么
老师,在ts里面提示类型报错显示有隐式的any
1.png
2.png
React Router如果要删除其他的就会报错,所以具体要删除一些什么
什么意思
export const { increment,decrement } = counterSlice.actions
这句话的意思是导出 increment,decrement, 并且increment,decrement = counterSlice.actions吗
3import withUserData from './components/withUserData'
4
5class UserView2 extends Component {
6 render() {
7 return (
8 <div>
9 <h3>我是第二个使用用户信息的界面</h3>
10 用户账号是:{this.props.userInfo.username}
11 </div>
12 )
13 }
14}
15
第10行为什么不可以是
用户账号是:{this.props.state.userInfo.username}
老师您好,我是在该文件创建好后,又进行了重命名把首字母大写了。但是在后续App.js中引用会报红色波浪线。
老师,我这样写完之后,在网页就开始报错了。课程这里面并没有在这块就报错这个报错我现在这节课需要关注吗?
老师,请问我在使用高阶组件的组件中(也就是课程中UView1.jsx中),想在生命周期函数中打印为什么undefined呢?
componentDidMount() {
//获取用户信息并存储在state中
console.log(this.props.userInfo)
但是像如下在render函数中直接使用却可以读取到数据。
<p>UserView1
username: {this.props.userInfo.username} nickname:{this.props.userInfo.nickname}</p>
高阶组件(HOC)本节课程中,05:52处。为什么在App.js中一开始使用的是函数式组件,然后给按钮增加事件会报错呢?
老师,想问下这里为什么把函数组件换成了类组件就可以实现点击事件且不报错了呢?
我添加用户,结果user数组变为undefined
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637