Похожие чаты

When do you have a situation where you manually set

an array index? Use splice or push If you must be alter the array

7 ответов

29 просмотров

My problem is that I'm not doing that :)) let history = [] const [shapes, setShapes] = useState([]) const handleUndo = useCallback(() => { if (!history.length) return history.pop() let isFound = false for (let i = shapes.length - 1; i >= 0; i--) { if (!history[history.length - 1]) return if (shapes[i].id === history[history.length - 1].id) { isFound = true shapes[i] = history[history.length - 1] break } } if (!isFound) { shapes.pop() } setShapes(shapes) }, [shapes])

Misan- Автор вопроса
Masoud
My problem is that I'm not doing that :)) let...

Oh they use the index as identifier for another array. Why not use the id property? It seems like a duplicated check. Unnecessary complexity

Masoud
My problem is that I'm not doing that :)) let...

heyyo how do you know when to use () or {} in code? [] is for array but I get confused with other brackets

12 Nothing
heyyo how do you know when to use () or {} in code...

The code that you saw above is react not vanila js :)

12 Nothing
heyyo how do you know when to use () or {} in code...

it's language syntax, you have to learn it according to the docs

12 Nothing
Ok i guess i shud focus more on docs ...

Learn primitive types vs reference types conditionals, guard clauses loops functions, passing functions to functions, returning functions from functions, arrow functions, iife array methods prototype chain event loop Destructing, spread Dom manipulation Promises, async await Make something small with it then you should be ready for a framework

Похожие вопросы

Обсуждают сегодня

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
any reference of this implementation?
BitBuddha
29
Ⓐrtto, [4/23/24 7:02 PM] Please explain more fully how it is not working exactly, and what are the steps you are taking, and what error messages come or what happens. Ⓐrtto, ...
Ezza Kezza
2
sounds like people have lost their kaspa on tradeogre... does this mean tradeogre not trustworthy?
Ezza Kezza
15
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
Недавно Google Project Zero нашёл багу в SQLite с помощью LLM, о чём достаточно было шумно в определённых интернетах, которые сопровождались рассказами, что скоро всех "ибешни...
Alex Sherbakov
5
So much speculation in the last week. So much volatility in price. This is because Hedera has a GC that isn't using the network it's governing. Why aren't people asking why a...
Summit Seeker R
9
Карта сайта