-
Notifications
You must be signed in to change notification settings - Fork 0
/
Filtering(app.jsx)
35 lines (30 loc) · 940 Bytes
/
Filtering(app.jsx)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import React, {useState, useEffect} from 'react';
require("es6-promise").polyfill();
require("isomorphic-fetch");
export default function App() {
const [data, setData] = useState([]);
const [q, setQ] = useState("");
useEffect(() => {
fetch("https://devmentor.live/api/examples/contacts?api_key=b7c58b")
.then(response => response.json())
.then((json) => setData(json));
},[])
function search(rows) {
return rows.filter(
(row) =>
row.firstName.toLowerCase().indexOf(q) > -1 ||
row.lastName.toLowerCase().indexOf(q) > -1 ||
row.lastName.toLowerCase().indexOf(q) > -1
);
}
return (
<div>
<div>
<input type="text" value={q} onChange={(e) => setQ(e.target.value)} />
</div>
<div>
<Datatable data={data}/>
</div>
</div>
);
}