React JS how to update ARRAYS in state 🍎

Поделиться
HTML-код
  • Опубликовано: 29 сен 2024

Комментарии • 27

  • @BroCodez
    @BroCodez  9 месяцев назад +3

    import React, { useState } from 'react';
    function MyComponent() {
    const [foods, setFoods] = useState(["Apple", "Orange", "Banana"]);
    function handleAddFood(){
    const newFood = document.getElementById("foodInput").value;
    document.getElementById("foodInput").value = "";

    setFoods(f => [...f, newFood]);
    }
    function handleRemoveFood(index){

    setFoods(foods.filter((_, i) => i !== index));
    }
    return (
    List of Food

    {foods.map((food, index) =>
    handleRemoveFood(index)}>
    {food}
    )}


    Add Food
    );
    }
    export default MyComponent;

  • @RychAhlberg
    @RychAhlberg 5 месяцев назад +6

    Bro, why use document.getElementById in React???

    • @totoroangelo0013
      @totoroangelo0013 3 месяца назад

      it is still javascript

    • @RychAhlberg
      @RychAhlberg 3 месяца назад

      ​I know but it's vanilla javascript. Very tedious.

    • @ulisesnava6834
      @ulisesnava6834 19 часов назад

      @@RychAhlberg and what we can use?

  • @ahmedelsehelly
    @ahmedelsehelly 9 месяцев назад +1

    Guys! You all Thank Bro like me for his effort to provide this awesome materials, so hasn’t the time come for us to thank our lord Allah who gives us an awesome brain to understand this masterpiece :) I really hope you all to wardship allah by the way he wants.

  • @Tendity
    @Tendity 9 месяцев назад +2

    I just want to say you have saved me SO MUCH time with your coding vids so thank you man

  • @otabekmadaminov-z2i
    @otabekmadaminov-z2i 22 дня назад

    Thank you very much bro

  • @frozenwater1017
    @frozenwater1017 3 месяца назад

    1:10 isn’t it division not development

  • @urvish_xyz
    @urvish_xyz 5 месяцев назад

    I found you accidentally ❤

  • @tataloo7314
    @tataloo7314 Месяц назад

    very good

  • @RED-so9mp
    @RED-so9mp 8 месяцев назад

    for deleting the elements can we use updater functions as well? like setFoods((f) => f.filter((_, i) => i !== index));

  • @raki0125
    @raki0125 9 месяцев назад

    Now i am pro in react pls do redux i will share this vid as possible

  • @--bountyhunter--
    @--bountyhunter-- 9 месяцев назад

    ey man, u and js mastery are the two most underrated creators i've seen
    u two deserve waay more subscribers than this
    tnx for all your efforts man . love ya

  • @Gian_sas
    @Gian_sas 9 месяцев назад

    thanks for your vids man, they are truly helpful 🙏 love from Argentina❤

  • @kuru6029
    @kuru6029 9 месяцев назад

    can you please create a video about how can your website send an email to someone?

  • @sidm5105
    @sidm5105 9 месяцев назад

    Bro Code your my favorite youtuber. Keep up this good work.

  • @_amonimus_
    @_amonimus_ 6 месяцев назад

    bro how many languages do you know

  • @maskedman0677
    @maskedman0677 9 месяцев назад

    Hey Bro code do you do a cybersecurity tutorial too ?

  • @rishabhkedia9304
    @rishabhkedia9304 8 месяцев назад

    Please make Reactjs projects as well

  • @l213dhanesh3
    @l213dhanesh3 9 месяцев назад

    Code bro i love u

  • @eharsha7389
    @eharsha7389 9 месяцев назад

    Good Explanation bro

  • @OCEMTechZone
    @OCEMTechZone 8 месяцев назад

    Great 🎉

  • @bartuskoprowski7543
    @bartuskoprowski7543 9 месяцев назад +1

    Amazing video i learned alot about ARRAYS in state

  • @karolkoprowski4539
    @karolkoprowski4539 9 месяцев назад +1

    Thanks for the video as always, bro

  • @kamranalizade98
    @kamranalizade98 9 месяцев назад

    The Best Coding Channel ever Thank you Bro code✌🙏