const createCounter = () => {
Frontend
What cookie settings are available (httpOnly, secure, expires, domain, path)?
const func = obj.sayHi() const boundFuns = func.bind(obj) boundFuns() ------------------- const submit = (el) => () => { log(el); } arr.map(el => <button onClick={submit(el)}/>) const param = useMemo(() => a + b) return <Child value={param} />
How do you understand what rendering in React is? What can cause it to happen?
import React, { useState, useEffect, useRef, useContext, useReducer, useMemo } from 'react'; export default Effects = () => { const [count, setCount] = useState(0); useLayoutEffect(() => console.log("each render 1")); console.log("each render 2"); useEffect(() => console.log("each render 3")); return ( <> <button onClick={() => setCount((prevProps) => ++prevProps)}> Increment </button> </> ) }
const obj = [{ value: 1, elems: [ { value: 2, elems: [ { value: 3 }, { value: 6 }, ... ] }, { value: 4, elems: [ { value: 5, elems: [ { value: 6 }, ... ]} ] } ] }] ------------- setTimeout(() => { console.log(1); }, 0); const p = new Promise(resolve => { console.log(2); resolve(); }); p.then(() => { console.log(3) }).then(() => { console.log(4); }); console.log(5);
Have you ever worked without an analyst, when you had to figure out the task on your own?
What is WeakMap?
const { foo: bar, bar: foo } = { foo: 1, bar: 2 } console.log(bar) // console.log(foo) //
How does React compare props? How does shallow comparison work?
Why is useRef needed? What are its applications?
const { foo: bar, bar: foo } = { foo: 1, bar: 2 }; //foo //bar setTimeout(() => { console.log("timeOut"); }, 0); console.log(1); new Promise((resolve) => { console.log("Promise"); setTimeout(() => { console.log("timeOut2"); resolve(); }, 0); }) .then(() => { console.log("then1"); }) .then(() => { console.log("then2"); }); console.log(4); setTimeout(() => { console.log("timeOut3"); }, 0);
let obj = { a: 1 }; let array = [obj]; obj = null; console.log(obj); // console.log(array); //
Type the getParam function so that TypeScript automatically highlights the presence of properties in the object. Make the typing so that arrays cannot be passed.
import { useState, useRef, useEffect } from "react"; const useDebugRender = ({props}) => { const prevProp = useRef(props) useEffect(() => { }, []) } const ParentComponent = () => { const [random, setRandom] = useState(0); // Passes to child component as a Prop const [text, setText] = useState(""); // Passes to child component as a Prop const createRandom = () => setRandom(Math.floor(Math.random() * 100)); const onTextChange = (e) => setText(e.target.value); const [count, setCount] = useState(0); const incrementCount = () => setCount((prev) => prev + 1); // This function is passed as a prop to the child component return ( <> <Count: {count} /> <input type="text" onChange={onTextChange} /> <button onClick={createRandom}>Generate Random</button> <div> <ChildComponent random={random} text={text} incrementCount={incrementCount} /> </div> </> ); }; export default ParentComponent;
const Effects = () => { const [count, setCount] = useState(0); useLayoutEffect(() => console.log("each render 1")); console.log("each render 2"); useEffect(() => console.log("each render 3")); return ( <> {count} <button onClick={() => setCount((prevProps) => ++prevProps)}> Increment </button> </> ); }; export default Effects; // 1 рендер: // После клика: const Effects = () => { const [count, setCount] = useState(0); const [number, setNumber] = useState(0); useEffect(() => { console.log(count); return () => { console.log(count); }; }); return ( <> {count} <button onClick={() => setCount((prevProps) => ++prevProps)}> Increment </button> </> ); }; export default Effects; // 1 рендер: // 2 1 3 // После клика: // 2 1 3 // return null: // 2 1 3 // // 1: 1, 0 // +: 1, 2 // ++: 2, 2
const submit = useCallback((el) => () => { log(el); }, []); arr.map(el => <button onClick={submit(el)} />) arr.map(el => <SomeComp key={} onClick={() => submit(el)} />) const param = useMemo(() => ({c: a + b}), [a,b]) return <Child value={param} /> Child = React.memo(() => {})
If the parent component passes a new array as props, will you see the new data on the screen or the old? Why?
Why debounce and not throttle for search?
Do let and const (hoisting) pop up? What happens when you access them before declaration?