-
Notifications
You must be signed in to change notification settings - Fork 0
fix: 更正按钮点击时,UI DOM展示state不一致问题,正确渲染list的长度,补充TS参数类型的定义 #3
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
| export default ({ initNumber = 0 }: ItemProps) => { | ||
| // 2. setstate 需要驼峰标识 | ||
| const [state, setState] = useState(initNumber); | ||
| const [flag, setFlag] = useState(true); |
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.
无意义,想太多了
| style={{ fontSize: '30px' }} | ||
| onClick={() => { | ||
| setstate(state + 1) | ||
| layoutEmitter.emit({ state }); |
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.
这删掉了,还怎么添加列表数据?
| onClick={() => { | ||
| setstate(state + 1) | ||
| layoutEmitter.emit({ state }); | ||
| setState(state => 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.
无意义修改,简写就行
| } | ||
| export default () => { | ||
| const [list, setList] = useState([]); | ||
| const [list, setList] = useState([] as Array<State>); |
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.
类型定义
useState()
| console.log(list); | ||
| setList(list); | ||
| // 4. list 为数组,引用数据类型,我们不能直接操作state要结构出来 | ||
| const listData = [...list] |
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.
假象,明天的考核中会有体现
| this.subscriptions(val); | ||
| }; | ||
|
|
||
| useSubscription = (callback: Subscription<T>) => { |
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.
无意义修改,这个文件无错误。
通过useEffect实现因为setState异步问题,不能把最新数据进行传递问题,补充TS参数的类型定义