Item List Manager

Sort by

recency

|

19 Discussions

|

  • + 1 comment
     const handleAddItem = () => {
        setItems(items, items.push(input))
        setInput("")
        console.log(items);
      };
    
  • + 0 comments

    const handleAddItem = () => { if (input.trim() !== "") { // Prevent adding empty or only-space items setItems([...items, input]); // Add the input to the list setInput(""); // Clear the input field } };

  • + 0 comments

    const handleAddItem = () => { if(input.length>0){ setItems([...items,input]) setInput("") } };

  • + 0 comments

    I learned about using .trim() to prevent empty values from being added to the list. If the input is just spaces or empty, .trim() helps catch that and avoids unwanted list items. This was a helpful tip and a plus point for me.

  • + 0 comments

    There’s more than one way to set up an input limiter, but most of the logic stays fairly consistent—something like if (input.length > 0) { setItems([...items, input]); setInput(""); } does the trick well. This pattern is especially handy when working with UI frameworks or even testing in Los emuladores de Android to simulate input behavior dynamically.