// 1.如果用的是class component,就在componentWillUnmount里面重置数据
componentWillUnmount(){
graph = null
nodes = []
edges = []
}
// 2.如果用的是function component,就在useEffect里面清除,第二参数空数组,相当于componentDidMount,只开始执行一次,里面return相当于componentWillUnmount
useEffect(() => {
// ....
return () => {
graph = null
nodes = []
edges = []
}
},[])
// 这样一来,再次进入页面的时候会重新调用graph = new G6.Graph({...}),重新生成canvas画布
// 问题描述:react函数组件中,在useEffect里面注册的graph = new G6.graph,graph.on('node:click',()=>{...})
export default function MapComponent() {
let graph = null
useEffect(() => {
graph = new G6.graph({})
// 如果在这边注册事件,就会变化一次注册一次事件,比如多加一个node
}, [nodes, edges])
// 必须重新写一个useEffect[]来为graph仅注册一次事件
useEffect(()=>{
graph.on('node:click',()=>{...})
},[])
}
// 添加样式:white-space:pre-line, normal模式下\n会转变为空格
const openNotification = () => {
notification.open({
message: 'Notification Title',
description:
'This is the content of the notification. \n This is the content of the notification.',
className: 'custom-class',
style: {
whiteSpace: 'pre-line',
},
});
};
1.先检查是否给formitem添加了唯一key
2.检查是否因为input的onChange事件做了setState操作,重复更新了input的数据
1.嵌套路由的重点在于,嵌套路由,不能在父级加 exact(精准匹配),因为先要匹配 父级 然后才能匹配 子集
2.比如:/nested/a , 会先匹配父级 /nested 后才能匹配 /nested/a