0.2.3 • Published 2 years ago

react-search-universal v0.2.3

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Installation

 npm i react-search-universal 

Usage

import React, { useState } from 'react';
import { Search } from 'react-search-universal';


function App() {

  const [value, setValue] = useState("");
  const onSearch = (val) => {
    setValue(val);
  }

  const data = [
    {
      name: "Carl",
      role: "Engineer",
    },
    {
      name: "Josh",
      role: "Doctor",
    },
    {
      name: "Mark",
      role: "Lawyer",
    },
    {
      name: "Karthik",
      role: "Architect",
    },
    {
      name: "Philips",
      role: "Actor",
    },
  ]

  const callback = (data) => {
    console.log(data);
  }
  return (
    <div className="App">
      <Search searchText={value} data={data} filteredData={callback} onSearchChange={onSearch}/>
    </div>
  );
}

export default App;

Props

PropDescription
searchTextSearch input field value - Required
onSearchChangeA function which acts as a callback when the input value is changed - Required
dataAn array of objects which acts as the source of data for filtering values based on search input - Optional
filteredDataA callback function which returns the filtered data from the source data based on the search input - Optional

License

MIT Licensed. Copyright (c) Hari Prasad 2022.