Skip to content

Conversation

@SunjianZheng
Copy link

No description provided.

style={{ fontSize: ".6rem" }} // fixed: 适配一下
onClick={() => {
setstate(state + 1);
layoutEmitter.emit({ state }); // unfixed: 父组件订阅不到初次的状态。 可以 emit({state + 1}),但不想被骂。
Copy link
Contributor

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

无意义注释

// list.push(data);

// fixed: 不能在 setState 外直接操作 state,react 数据的不可变性。
// 直接操作 state 会导致之前的变更无效(应该是这个原因),所以 DOM 不会重新渲染。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

未找到关键原因。明天的考察中有体现,敬请期待。

return;
}
});
}, [list.length]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

监听无意义,扣点分吧

<p>list length:{list.length}</p>
{
list.map(({ state }) => (
<p key={`_${state}`}>{state}</p>
Copy link
Contributor

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 未初始化,不是个对象,会报错。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

无用注释,都不要留着。
我不骂你,扣点分,不过分吧?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants