当前位置: 首页 > 面试经验 >

mmt前端日常实习一面

优质
小牛编辑
95浏览
2023-07-06

mmt前端日常实习一面

mmt

一面

1. 自我介绍

2. 吹项目,吹了很久

3. react都有哪些hook,https://react.dev/reference/react#other-hooks,组件的传输方式?包括ref

const MyInput = forwardRef((props, ref) => {
    useImperativeHandle(ref, () => ({
        /* code here */
    }), [])  
})

4. react获取上一轮的props和state

function PrevState() {
  const [count, setCount] = useState(0)

  const prevCountRef = useRef()
  
  /*
      useEffect(() => {}, []):只在组件挂载时执行一次,不会在组件更新时再次执行。
      useEffect(() => {}):在组件挂载时执行一次,并在每次组件更新时都会再次执行。
  */
  useEffect(() => {
    prevCountRef.current = count;
  })
  
  const handleClick = () => {
    setCount(count+1)
  }
  
  return (
    <>
      <button onClick={handleClick}>+1</button>
      <h1>Now: {count}, before: {prevCountRef.current}</h1>
    </>
  )
}

5. redux的概念(怎么工作的,说真的没思考过这些问题,都是拿来即用,还是要思考一下)https://redux.js.org/understanding/thinking-in-redux/glossary

- reducer: This is a reducer - a function that takes a current state value and an
action object describing "what happened", and returns a new state value.
A reducer's function signature is: (state, action) => newState

6. 知不知道cookie, 有什么用,能不能设置过期时间?

7. Cookie, SessionStorage, LocalStorage区别?

8. 问用没用过lodash,我说lodash.merge, lodash.get, set之类的

9. limitPromise

function limitConcurrency(tasks, limit) {
  return new Promise((resolve, reject) => {
    let results = [];
    let runningCount = 0;
    let currentIndex = 0;


    function runTask(index) {
      if (index >= tasks.length) {
        resolve(results);
        return;
      }


      runningCount++;
      tasks[index]()
        .then((result) => {
          results[index] = result;
          console.log(result)
        })
        .catch((error) => {
          results[index] = error;
        })
        .finally(() => {
          runningCount--;
          runTask(currentIndex++);
        });


      if (runningCount < limit) {
        runTask(currentIndex++);
      }
    }


    runTask(currentIndex);
  });
}


// 测试案例
const tasks = [
  () => new Promise((resolve) => setTimeout(() => resolve(1), 1000)),
  () => new Promise((resolve) => setTimeout(() => resolve(2), 2000)),
  () => new Promise((resolve) => setTimeout(() => resolve(3), 1500)),
  // ...
];

limitConcurrency(tasks, 2)

面试官人很好,很和善,但是我太久没背八股了,考完试回来后就看了一小时上场了,感觉对不起他

 类似资料: