How to access the onchange text in a react-select search component

I'm currently working on implementing search select functionality in my webpage using the react-select-search npm package.

This is my main component:

import React, { Component } from "react";
import Task from "./task";

// Rest of the code...

The Task component utilizes the selectSearch package:

import React from "react";
import DatePicker from "react-datepicker";
import SelectSearch from "react-select-search";
import "react-datepicker/dist/react-datepicker.css";
import "./tasklist.css";
const Task = (props) => {

// Rest of the code...

Currently, I have managed to retrieve the selected text using the onChange function in the package. However, my goal is to capture the typed text as we type into the input box. I attempted to pass the onKeyUp props to the selectSearch component and access the value 'e' in a function, but I was unsuccessful. Is there a way to accomplish this?

Answer №1

Upon reviewing the documentation, I stumbled upon a helpful prop called getOptions that allows us to retrieve the search query passed to the component and then save it in a state for persistence in field values.

Check out this link for more information

This is what I did:

I included getOptions={myFunction} in the component and enabled search={true}

const [chosenTask, setChosenTask] = useState(null);
 <SelectSearch
            options={props.statusOptions}
            id="input1"
            getOptions={myFunction}
            onChange={(data) => props.selectOptionChange(data, task.id)}
            name="taskStatus"
            search={true}
            data-id={idx}
            value={task}
            placeholder="Choose task status"
          />

const myFunction = (value) => {
setChosenTask(value);
}

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

Set the error state of a TextField in Material UI to true based on the user's input

Being a newcomer to React and Javascript, I have made some progress but now find myself stuck. I am struggling with how to change the error state of a Material UI TextField based on user input. Specifically, I want the error to be triggered if the user inp ...

Tips for sending props to MUI styled menu for creating specific conditional styling effects

Is it possible to pass props to an already styled Material-UI menu with conditional styling for different minimum widths? The issue I am facing is that the menu's styles are outside of the component receiving the props, so how can I achieve this? c ...

Help Needed: Adding a Simple Element to jQuery Tabs Script

I recently came across a fantastic jQuery tabs script on a website called Tutorialzine. The link to the article can be found here. As I was implementing this script, I realized I needed to customize it by adding specific classes to certain tabs. Specifica ...

Is there a way in MVC3 / .net4 to convert a JSON formatted JavaScript array into a C# string array?

I am facing a challenge with my MVC3/.Net service where it is receiving arguments in the form of a JSONified Javascript array. I want to convert them into a C# array of strings. Is there a built-in solution available for this task, or do I need to create ...

What is the best way to use multiple encoding types when sending data via a POST method in Node.js?

My current challenge involves sending a combination of name and description text data alongside a video file. Unfortunately, I've encountered an issue where I can only send either the video or the text, but not both simultaneously. Below is the code ...

Looking to spice up your static HTML site? Dive into the world of Ruby on

I recently developed an app that features a static HTML webpage containing text and images, and now I'm interested in incorporating Ruby on Rails to explore its capabilities further. After creating a basic RoR application, I copied the HTML content f ...

Changing the theme of a toggle button in Jquery Mobile when the button is pressed

I have a group of buttons with a specific class <div class="prog-day"> <div class="prog-clear" data-role="controlgroup" data-type="horizontal> <a href="#" data-role="button" data-mini="true" data-theme="b">Clear</a> ...

The Safari 7.1+ browser seems to be having trouble with the spotlight effect

Why is the CodePen not functioning properly in Safari? Despite working well in Chrome and Firefox, it completely fails to work in Safari 7.1+. Can anyone provide some insights? http://codepen.io/cchambers/pen/Dyldj $(document).on("mousemove", function( ...

Error: Express JS custom module cannot be located in the root directory's modules folder

The file structure of my express js app resembles this I'm attempting to load a modules folder from the root directory. routes/users.js var express = require('express'); var router = express.Router(); var md=require('./modules') ...

Show text upon hovering using jQuery

I am currently exploring jquery and trying to implement a functionality where text is displayed upon hovering over a div element. My basic html page consists of squares, with one of them rotating when a button is clicked. I now want to show some text withi ...

Tips for successfully sending an array via an XMLHttp Get request

I am currently working on a project where I need to utilize all the values from an array in my GET request. The code snippet below outlines my approach: function executeRequest(){ let data = ['value1', 'value2', 'value3'] ...

Sending information from the backend to the frontend using Node.js and Express

I am seeking advice on the most effective method for achieving a specific task. In my Node.Js / Express application, there is a point where I need to send data to the backend and receive a certain value back to the front end. Typically, this can be accomp ...

Universal MUI theme for various projects

After successfully creating a theme for my project using createTheme, I find myself wondering how to efficiently use that same theme for future projects without having to constantly copy it over. Upon reaching out to the Mui team with this question, their ...

How can I securely save a user's login information using ExtJS without saving it multiple times?

Currently, I am utilizing Ext.Ajax.request() to access a PHP page that provides user-specific information during the login process. In order to store variables such as cookies and session information in ExtJS, I have created a model with necessary fields a ...

How can I showcase both a username and email address in a Material UI chip?

I'm currently using Material UI chip to show name and email next to each other. However, when the name is long, the email goes beyond the chip boundary. Here's my function that generates the chips: getGuestList() { let {guests} = this.sta ...

What is the best way to declare a variable while rendering HTML in a ReactJS loop?

render() { return ( <ul> {scopeOptions.map((option, keyOption) => ( const myVar = keyOptions * 5 <li key={keyOption}> <a href="#" data-value={option.value}>{option.label}</a> </li> ))} </ul> ) } I ...

Error: npm script cannot find the specified module in the directory

I'm facing an issue while trying to run a ReactJS application on my Windows 10 machine using npm. When running the execution script, I encounter a compilation error saying: Module not found: Can't resolve '../assets_new/fonts/lato_bold.woff ...

Exploring Node.js with a straightforward illustration and tackling the EPERM error

const server = require('http').createServer(function(req, res){ }); server.listen(8080); This code snippet is causing an error to be displayed in the console: $ node node_server.js node.js:201 throw e; // process.nextTick error, or &apos ...

What could be causing the data in the data table to remain undeleted unless the page is manually refreshed

I am facing an issue with the delete button functionality. When I press the button, it successfully deletes the row but requires a page refresh to make the deleted row disappear. How can I resolve this problem and ensure that the row is deleted without the ...

Tips for ensuring a controller function only runs once in AngularJS

I have a controller that is being referenced in some HTML. The HTML changes on certain events, causing the controller function code to execute multiple times. The issue lies in a portion of the code that should only be executed once. Shown below is the ...