const createCounter = () => {
Frontend
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> </> ) }
What are the scopes of let/const and var? Is there another way to declare variables besides var, let, const?
What cookie settings are available (httpOnly, secure, expires, domain, path)?
How do you understand what rendering in React is? What can cause it to happen?
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} />
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) //
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);
How does React compare props? How does shallow comparison work?
Why is useRef needed? What are its applications?
If the parent component passes a new array as props, will you see the new data on the screen or the old? Why?
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.
let obj = { a: 1 }; let array = [obj]; obj = null; console.log(obj); // console.log(array); //
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
What is the difference between sequential await p1, await p2 and Promise.all([p1, p2])?
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(() => {})
Do let and const (hoisting) pop up? What happens when you access them before declaration?