search bar in react js example
// App.js
import React, { useState, Fragment } from "react";
import List from "./List";
const App = () => {
const [userInput, setUserInput] = useState("");
const [list, setList] = useState([
"walk the dog",
"buy the milk",
"learn some code"
]);
// userinput is controlled by the App component
const handleChange = e => {
setUserInput(e.target.value);
};
const addItem = e => {
if (userInput !== "") {
setList([...list, userInput]);
setUserInput("");
}
};
const removeItem = item => {
const updatedList = list.filter(listItem => listItem !== item);
setList(updatedList);
};
return (
<Fragment>
<List list={list} removeItem={removeItem} />
<hr />
<form>
<input
placeholder="Something that needs to be done..."
value={userInput}
onChange={handleChange}
/>
<button type="button" onClick={addItem}>
{'Add Item'}
</button>
</form>
</Fragment>
);
}
export default App;
Also in JavaScript:
- collision detection three js
- how to print numbers in javascript
- angular prod apache config for route
- append css file with javascript
- react $ r component instance console
- javascript document.createElement add function
- ajax data not reflecting after refresh particular div jquery
- indexof javascript duplicate arrays
- see if discord message is in dm discord.js
- react native background image
- js class async constructor
- js filter
- ajax call do something while
- textinput onpress react native
- if string have any digits javascript
- import json file javascript
- how to find dates in a string in js
- ion button transparent
- jquery dialog button text set by variable
- how to make a factorial function in javascript
- javascript es6 class
- electron send message from renderer to main
- React site warning: The href attribute requires a valid address. Provide a valid, navigable address as the href value jsx-a11y/anchor-is-valid
- ejs / javascript check if array/object exists and is not empty