Skip to content

Conversation

@JayceV552
Copy link

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

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

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

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]
Copy link
Contributor

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>) => {
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