fix: 1.在state外操作state;2.map缺少key;3.类型定义;4.行内样式修正;#2
Open
SunjianZheng wants to merge 2 commits intomasterfrom
Open
fix: 1.在state外操作state;2.map缺少key;3.类型定义;4.行内样式修正;#2SunjianZheng wants to merge 2 commits intomasterfrom
SunjianZheng wants to merge 2 commits intomasterfrom
Conversation
xiaohuoni
reviewed
Jul 28, 2020
| style={{ fontSize: ".6rem" }} // fixed: 适配一下 | ||
| onClick={() => { | ||
| setstate(state + 1); | ||
| layoutEmitter.emit({ state }); // unfixed: 父组件订阅不到初次的状态。 可以 emit({state + 1}),但不想被骂。 |
| @@ -1,15 +1,29 @@ | |||
| import React, { useState } from 'react'; | |||
| import { layoutEmitter } from '@/utils/EventEmitter'; | |||
| // import React, { useState, useEffect } from 'react'; | |||
src/pages/index.tsx
Outdated
| // list.push(data); | ||
|
|
||
| // fixed: 不能在 setState 外直接操作 state,react 数据的不可变性。 | ||
| // 直接操作 state 会导致之前的变更无效(应该是这个原因),所以 DOM 不会重新渲染。 |
src/pages/index.tsx
Outdated
| return; | ||
| } | ||
| }); | ||
| }, [list.length]); |
src/pages/index.tsx
Outdated
| <p>list length:{list.length}</p> | ||
| { | ||
| list.map(({ state }) => ( | ||
| <p key={`_${state}`}>{state}</p> |
| layoutEmitter.emit({ state }); | ||
| }} | ||
| >EventEmitter {state} </button> | ||
| // useEffect(() => { // unfixed: 可以在这里解决,但第一次 this._subscription 未初始化,不是个对象,会报错。 |
Contributor
There was a problem hiding this comment.
无用注释,都不要留着。
我不骂你,扣点分,不过分吧?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.