-
Notifications
You must be signed in to change notification settings - Fork 0
fix: 1.在state外操作state;2.map缺少key;3.类型定义;4.行内样式修正; #2
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
base: master
Are you sure you want to change the base?
Conversation
| style={{ fontSize: ".6rem" }} // fixed: 适配一下 | ||
| onClick={() => { | ||
| setstate(state + 1); | ||
| layoutEmitter.emit({ state }); // unfixed: 父组件订阅不到初次的状态。 可以 emit({state + 1}),但不想被骂。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
| @@ -1,15 +1,29 @@ | |||
| import React, { useState } from 'react'; | |||
| import { layoutEmitter } from '@/utils/EventEmitter'; | |||
| // import React, { useState, useEffect } from 'react'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
无意义注释
src/pages/index.tsx
Outdated
| // list.push(data); | ||
|
|
||
| // fixed: 不能在 setState 外直接操作 state,react 数据的不可变性。 | ||
| // 直接操作 state 会导致之前的变更无效(应该是这个原因),所以 DOM 不会重新渲染。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
未找到关键原因。明天的考察中有体现,敬请期待。
src/pages/index.tsx
Outdated
| return; | ||
| } | ||
| }); | ||
| }, [list.length]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
监听无意义,扣点分吧
src/pages/index.tsx
Outdated
| <p>list length:{list.length}</p> | ||
| { | ||
| list.map(({ state }) => ( | ||
| <p key={`_${state}`}>{state}</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加下划线太多余。扣点分吧
| layoutEmitter.emit({ state }); | ||
| }} | ||
| >EventEmitter {state} </button> | ||
| // useEffect(() => { // unfixed: 可以在这里解决,但第一次 this._subscription 未初始化,不是个对象,会报错。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
无用注释,都不要留着。
我不骂你,扣点分,不过分吧?
No description provided.