Похожие чаты

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 ответов

11 просмотров

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

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

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

Есть рассчет для Таллинна? https://x.com/dr_enderlin/status/1784581592003850496
Vladimir Ivanov
23
а зачем этот вопрос для удаления из чата?
Mёdkinson Medvezhkin
63
Добрый день. Хочу сделать отрисовку по команде на панели. Почему-то рисуется только при втором вызове. С чем может быть связано, не подскажете? procedure TForm1.FormDblClick(...
Kirill Filippenok
20
Any dog on Fantom ?
Bitcoin Magic
19
Добрый день Как поставить vscode из флэтпака как дефолтный редактор в filezilla?
Daniel
18
Интересно, а в чём прикол мак оси?
Лисицка
16
main.c #include <fenv.h> #include <stdio.h> int main(void) { constexpr float f = 23.0f; constexpr float g = 33.0f; fesetround(FE_TOWARDZERO); constexpr float...
mito 😼
2
Всем доброго дня! Подскажите может кто использовал связку Pagebuilder + Clientsetting. Сами параметры с типом pagebuilder в модуле Clientsetting работают нормально, можно такж...
Александр Добриков
12
using next image component with s3 image: "url" parameter is valid but upstream response is invalid code: <Image fill src={s...
Fasil
3
Tax his land, Tax his bed, Tax the table At which he's fed. Tax his work, Tax his pay, He works for peanuts Anyway! Tax his cow, Tax his goat, Tax his pants, Tax his coat....
Forge
5
Карта сайта