React JS how to update ARRAYS in state 🍎

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

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

  • @BroCodez
    @BroCodez  11 месяцев назад +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;

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

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

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

    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

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

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

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

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

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

    Amazing video i learned alot about ARRAYS in state

  • @karolkopr
    @karolkopr 11 месяцев назад +1

    Thanks for the video as always, bro

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

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

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

      it is still javascript

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

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

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

      @@RychAhlberg and what we can use?

  • @alanit8459
    @alanit8459 2 дня назад

    Hello bro code, you are truly a professor. I miss you very much. Thank you. I have a question. If you want to add the item to Array
    exam:function addItemCorrect(item) {
    setItems(prevItems => [...prevItems, item]); // This correctly creates a new array.
    }
    its not work to add array
    i see this way in site mastering react to do that just your way to add array or what
    please answer me

  • @ahmedelsehelly
    @ahmedelsehelly 11 месяцев назад +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.

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

    Good Explanation bro

  • @otabekmadaminov-z2i
    @otabekmadaminov-z2i 2 месяца назад

    Thank you very much bro

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

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

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

    Please make Reactjs projects as well

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

    The Best Coding Channel ever Thank you Bro code✌🙏

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

    very good

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

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

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

    Hey Bro code do you do a cybersecurity tutorial too ?

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

    1:10 isn’t it division not development

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

    Great 🎉

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

    bro how many languages do you know

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

    I found you accidentally ❤

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

    Code bro i love u

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

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