Displaying entries of input data

I have an application that includes a modal window with filters, but I am looking to add another type of filter. However, I am struggling with implementing it in React and would appreciate any help with the code or recommended links.

Essentially, I want to allow users to input their own values into a line within the filters, press Enter, and see the entered result displayed (users should be able to enter multiple values for filtering purposes).

If my explanation seems confusing, I can also provide a screenshot illustrating the desired outcome:

https://i.stack.imgur.com/YpmnS.png

Answer №1

To enhance the user interface, consider utilizing a custom input field like the one demonstrated here: .

For incorporating this functionality into your project:

const list =  [2,3,4,56,7,8,12,34,0,1]
const searchedItems =  [3,7,8]
const finalList= [];
function searchItems() {
   list.forEach(item => {
     searchedItems.forEach(ele => {
       if(ele===item) finalList.push(item);
   })
  });
  return finalList;
}
console.log(searchItems())

Don't forget to integrate this array with your search item results for a seamless user experience.

Answer №2

export function ListItem({ itemValue }) {
  return (
    <div className="item">
      <span className="itemValue">{itemValue}</span>
    </div>
  );
}

export default function App() {
  const [itemList, setListItem] = useState([]);
  const [item, setItem] = useState("");
  const addValue = (event) => {
    setItem(event.target.value);
  };
  const listenEnter = (event) => {
    if (event.key === "Enter" && event.target.value !== "") {
      setListItem([...itemList, item]);
      setItem("");
    }
  };
  return (
    <div className="App">
      <input
        className="inputElement"
        placeholder="Enter Value"
        value={item}
        onChange={addValue}
        onKeyUp={listenEnter}
      />
      <div className="itemList">
        {itemList.map((item) => (
          <ListItem itemValue={item} />
        ))}
      </div>
    </div>
  );
}

Original code available at this link

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The issue lies with the React router not functioning properly when handling root

My React Router is functioning correctly, but I encounter an error when adding params to the router. The specific error displayed is "Uncaught SyntaxError: Unexpected token <". import React from 'react'; import ReactDOM from 'react-dom ...

Ensuring that a Box retains its visual appeal even as the screen size fluctuates within MaterialUI in ReactJS

Struggling with a minor yet bothersome issue related to an Avatar within my MaterialUI sidebar. Trying to maintain the proportion of this wrapped Avatar image(Link: https://i.stack.imgur.com/lt1Lj.png) as the screen size changes, but it slowly disappears ...

react-oidc-context automatically redirects to the original route upon successful login using Auth0

Greetings! I am currently attempting to implement authentication using react-oidc-context with auth0, but I have encountered an issue. Upon successful authentication with auth0, I always get redirected back to the route I was on when I clicked the login bu ...

There seems to be a hiccup in the JavaScript Console. It could potentially impact the functionality

Hey there, I'm encountering a strange issue in my IE 11 console. A JavaScript Console error has occurred. This may impact functionality. Whenever I try to run a for loop to create a list of elements within a ul tag 4000 times, the process stops at ...

Develop a Modal Form using Bootstrap (HTML)

I followed a tutorial on creating a modal form with Bootstrap, you can find it here: http://www.youtube.com/watch?v=HCEbp07hfLw I replicated the steps shown in the video, but when I try to open the page in my browser, nothing appears. I have added the Bo ...

Are there any solutions for the malfunctioning v8 date parser?

The V8 Date parsing functionality is not functioning properly: > new Date('asd qw 101') Sat Jan 01 101 00:00:00 GMT+0100 (CET) I have attempted to use a delicate regular expression like the following: \d{1,2} (jan|feb|mar|may|jun|jul|a ...

What is the best way to dynamically assign a value to an anchor tag upon each click using jQuery?

How can I pass a value to an anchor tag on every click using jQuery? I am encountering an issue with my current code where the value is not being retrieved when I click the button. //HTML snippet <button id="a-selectNm" data-a_name="<?php echo $row[ ...

The elastic image slideshow maintains the original size of the images and does not resize them

When utilizing the elastic image slider, I encounter a similar issue as described at Elastic Image Slideshow Not Resizing Properly. In the downloaded example, resizing the window works correctly. However, when trying to integrate the plugin with Twitter B ...

Click on the link or tab to update the marker location on the Google Map

Can you click on Tab 2 to change the marker/location, and then go back to Tab 1 to switch it back to the original location? [Links to Fiddle] http://jsfiddle.net/ye3x8/ function initialize() { var styles = [{ stylers: [{ saturati ...

Is it possible to integrate ng-repeat with ng-model in Angular?

Is it possible to link the ng-model of a button with the ng-repeat loop? <a ng-repeat="x in [1,2,3,4]" ng-model="myButton[x]">{{myButton[x]}}</a> In the Controller: var id = 4; $scope.myButton[id] = ' :( '; I am interested in crea ...

What strategies can I implement to keep my Nextjs App logged in?

What steps can I take to keep regular users from needing to log in every time they visit the website in a NextJs (ReactJs) environment? ...

Uploading with Javascript CORS consistently ends with an error event occurring

My current challenge is uploading a file to a server using JavaScript in compliance with the CORS specification. While there are numerous examples available online that successfully upload the file, I encounter an error as the final event being fired. Up ...

Is the condition failing to evaluate for all td elements?

I am currently dealing with an HTML table. When I select a checkbox, I aim to compare the values of the cells in each row. This comparison works correctly for the first row, but it does not work for any subsequent rows. HTML Code - <form role="fo ...

"Unable to execute validateOptions as it is not a recognized function

ERROR src/pages/trade/trade-sagas/trade-sagas.unit.test.js ● Test suite failed to run Cannot locate module 'axios' from 'src/pages/trade/trade-sagas/trade-sagas.unit.test.js' 1 | import { runSaga } from "redux-saga"; &g ...

Creating a responsive Material UI Container Component is imperative for ensuring a user

Is there a way to have the Container Component with a maxWidth Prop that changes based on Theme Breakpoints? If not, what is the best approach to achieve this functionality? ...

Using the POST method in Node.js is not functioning properly on the Replit server when using express

Recently diving into the world of backend development, I have been utilizing Node.js on a Replit server with express to host an application for handling files: However, hitting a roadblock when attempting to execute a post request! var express = ...

Using e.preventDefault in my code is causing obstacles when I try to conduct unit testing with En

I developed a reactJS application which includes a button for users. When the user clicks on the button, they receive a verification code on their cellphone. Initially, there was an issue where the form would randomly refresh when the button was clicked. ...

"Enhance your website with a dynamic Jssor slider featuring nested slides and vertical

Exploring the idea of merging the nested slider feature with a vertical thumbnail display. Reviewing the source code for examples image-gallery-with-vertical-thumbnail.source.html and nested-slider.source.html, I am wondering how to effectively combine t ...

"Initiate React app with specific port number using the Command Line Interface

I'm trying to launch my react server on Linux CLI with a specific port number without modifying the package.json script. I want the ability to run multiple react instances on different ports via CLI. I've come across suggestions like npm start ...

What is the best approach to updating multiple rows instead of just the first row using the update button located on both sides using PHP and AJAX?

Starting fresh, so I might sound like a beginner with this question. How can I make use of the update button to update specific rows instead of just the top row? Every time I try to update, it only works for the top row. Here's the code snippet from ...