To set some context: I have an API that returns an array of key/value pairs. I want to add a feature that displays each Key/Value on the webpage when it loads (done) and implement a "Search" on this list using a text box, where as users type, the list shrinks to only matching keys.
Relevant React code looks as follows:
var PropEntry = function PropEntry(p) {
var displayValue = React.createElement(
"span",
null,
p.value
);
var valueMarkup = React.createElement(
"div",
null,
React.createElement(
"span",
{ className: "prop-value" },
displayValue
);
return React.createElement(
"div",
{ className: "prop-entry" },
React.createElement(
"label",
null,
p.name
),
valueMarkup
);
};
var ColsView = function ColsView(props) {
var cols = props.streamCols;
return React.createElement(
"div",
{ className: "named-container" },
React.createElement(
"input",
{ type: "text", placeholder: "Search", onChange: <CallFunctionHere> }),
React.createElement(
"div",
{ className: "named-entries" },
cols.map(function (col) {
return React.createElement(PropEntry, { name: col.Name, value: col.value });
})
)
)
}
ColsView = ReactRedux.connect(function (state) {
return { streamCols: state.streamCols };
})(ColsView);
I'm trying to add a textbox just above the list that filters this list as users type (onChange keystroke). What would be the best way to do this? I would like to avoid calling the API another time since I already have the full list of items.
I should also mention that I'm very much a beginner with React and I'm just trying to add features to an existing .js file that I do not wish to rewrite completely :)
values.filter(value => value.match(/<some regex>/g))Thesome regexcould naively be the value you are trying to filter by, but it's easy to get more complicated than that very quickly. On the way more complicated side of things, you can do things such as tokenization and building search trees, all of which are their own massive topics.textbox, or any type ofinputfor that matter, in your code.