1、Route里边的element需要填写一个组件而不是一个函数组件名称
<Route path="/login" element={<Login />}></Route>
2、类组件里边this丢失问题
将this.handler赋予给onClick 其中handler当中的this指向为window,可以将handler写为箭头函数
3、类组件里边状态值需要卸载state 里边,并且通过setState进行修改
4、通过createContext创建容器,读取生产者的值
function Son(){
return (
<div>
<MyContext.Consumer>
{/*注意读取时候一定要放在Consumer直接下面*/}
<div>{value=>(<p>{value.age}</p>)}</div>
</MyContext.Consumer>
</div>
)
}
5、类组件的constructor当中调用super
constructor(props) {
// 直接调用super
super(props)
}
6、给插槽传递内容,如果传递多个标签或者内容,需要通过遍历进行展示
7、通过Context将store作为基础内容
class IndexStore {
constructor() {
this.countStore = new CounterStore()
this.userStore = new UserStore()
}
}
// 其中CounterStore 等都作为属性方式写入 跟读取普通的context差不多
export default createContext(new IndexStore())