Skip to content

Instantly share code, notes, and snippets.

@alonbardavid
Created October 2, 2019 12:31
Show Gist options
  • Save alonbardavid/12b23ea73da8d0f484c83730bf170502 to your computer and use it in GitHub Desktop.
Save alonbardavid/12b23ea73da8d0f484c83730bf170502 to your computer and use it in GitHub Desktop.
Patterns for deriving state gist11
function sortedList(props){
const {list) = props;
const [filter, setFilter] = useState("");
const [sortKey, setSortKey] = useState(null);
const filteredList = list.filter(item=>item.text.indexOf(filter)>=0)
const sortedList = list.sort((a,b)=>a[column]>b[column]?1:a[column] < b[column]?-1:0);
return <div>
{sortedList.map(item=>
<ItemView item={item} key={item.id} />
)}
<button onClick={()=>setSortKey("columnA")}>Sort by A</button>
<button onClick={()=>setSortKey("columnB")}>Sort by B</button>
<input type="text" value={filter}
onChange={setFilter}>Sort by A</button>
</div>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment