React JS how to update ARRAYS in state 🍎

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

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

  • @BroCodez
    @BroCodez  Год назад +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 Год назад +2

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

  • @--bountyhunter--
    @--bountyhunter-- Год назад

    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 Год назад

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

  • @Gian_sas
    @Gian_sas Год назад

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

  • @nadicadizdarevic2835
    @nadicadizdarevic2835 28 дней назад

    Thanks from Serbia.

  • @bartuskoprowski7543
    @bartuskoprowski7543 Год назад +1

    Amazing video i learned alot about ARRAYS in state

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

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

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

      it is still javascript

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

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

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

      @@RychAhlberg and what we can use?

  • @eharsha7389
    @eharsha7389 Год назад

    Good Explanation bro

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

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

  • @karolkopr
    @karolkopr Год назад +1

    Thanks for the video as always, bro

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

    Thank you very much bro

  • @kamranalizade98
    @kamranalizade98 Год назад

    The Best Coding Channel ever Thank you Bro code✌🙏

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

    very good

  • @maskedman0677
    @maskedman0677 Год назад

    Hey Bro code do you do a cybersecurity tutorial too ?

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

    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

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

    Please make Reactjs projects as well

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

    Great 🎉

  • @kuru6029
    @kuru6029 Год назад

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

  • @ahmedelsehelly
    @ahmedelsehelly Год назад +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.

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

    1:10 isn’t it division not development

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

    bro how many languages do you know

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

    I found you accidentally ❤

  • @raki0125
    @raki0125 Год назад

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

  • @l213dhanesh3
    @l213dhanesh3 Год назад

    Code bro i love u