Created
October 2, 2019 12:31
-
-
Save alonbardavid/12b23ea73da8d0f484c83730bf170502 to your computer and use it in GitHub Desktop.
Patterns for deriving state gist11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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