Skip to content

fix: 更正按钮点击时,UI DOM展示state不一致问题,正确渲染list的长度,补充TS参数类型的定义#3

Open
JayceV552 wants to merge 1 commit intomasterfrom
dev-LiJunCai
Open

fix: 更正按钮点击时,UI DOM展示state不一致问题,正确渲染list的长度,补充TS参数类型的定义#3
JayceV552 wants to merge 1 commit intomasterfrom
dev-LiJunCai

Conversation

@JayceV552
Copy link
Copy Markdown

通过useEffect实现因为setState异步问题,不能把最新数据进行传递问题,补充TS参数的类型定义

export default ({ initNumber = 0 }: ItemProps) => {
// 2. setstate 需要驼峰标识
const [state, setState] = useState(initNumber);
const [flag, setFlag] = useState(true);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

无意义,想太多了

style={{ fontSize: '30px' }}
onClick={() => {
setstate(state + 1)
layoutEmitter.emit({ state });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这删掉了,还怎么添加列表数据?

onClick={() => {
setstate(state + 1)
layoutEmitter.emit({ state });
setState(state => state + 1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

无意义修改,简写就行

Comment thread src/pages/index.tsx
}
export default () => {
const [list, setList] = useState([]);
const [list, setList] = useState([] as Array<State>);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

类型定义
useState()

Comment thread src/pages/index.tsx
console.log(list);
setList(list);
// 4. list 为数组,引用数据类型,我们不能直接操作state要结构出来
const listData = [...list]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

假象,明天的考核中会有体现

Comment thread src/utils/EventEmitter.ts
this.subscriptions(val);
};

useSubscription = (callback: Subscription<T>) => {
Copy link
Copy Markdown
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.

2 participants