codeType
1. 自我介绍
2. 在工作中遇到的具有挑战性的事
3. react的常用hooks
4. 实现useHandler
5. 事件循环输出题
1.在工作中遇到的具有挑战性的事
讲了我实现的前端埋点库
2. 实现useHandler
js
const A = (props) => {
const [state,setState] = useState({b:1})
const handler = useHandler((event) => {
console.log(props.a);
console.log(state.b);
});
return <button onClick={handler}>click me</button>;
};
// handler 引用稳定不变,每次执行获取到的 props、state 都是最新的
const useHandler = (cb) => {
}
3. 事件循环
js
async function async1() {
console.log("async1 start");
await async2();
console.log("async1 end");
Promise.resolve().then(() => {
console.log("after async1 end");
});
}
async function async2() {
console.log("async2");
}
console.log("script start");
setTimeout(() => console.log("setTimeout"), 0);
async1();
new Promise((resolve) => {
console.log("promise1");
resolve();
}).then(() => {
console.log("promise2");
});
console.log("script end");
的输出顺序