Skip to content

Instantly share code, notes, and snippets.

@skflowne
Created August 15, 2020 14:54
Show Gist options
  • Save skflowne/c77436e95659da5eaf9240d9e635acdb to your computer and use it in GitHub Desktop.
Save skflowne/c77436e95659da5eaf9240d9e635acdb to your computer and use it in GitHub Desktop.
import React from "react"
import styled from "styled-components"
import { useRecoilState } from "recoil"
import { currentStatState, availableStats } from "../../state/app"
const StyledCurrentStatSelect = styled("div")`
display: flex;
flex-flow: column;
align-items: center;
position: absolute;
top: 1rem;
right: 1rem;
z-index: 50;
width: 10%;
select {
padding: 0.5rem;
border: none;
width: 100%;
}
`
const CurrentStatSelect = () => {
const [currentStat, setCurrentStat] = useRecoilState(currentStatState)
const handleStatChange = (e) => {
const newStat = e.target.value
setCurrentStat(newStat)
}
return (
<StyledCurrentStatSelect>
<select value={currentStat} onChange={handleStatChange}>
{availableStats.map((stat) => {
return (
<option key={stat} value={stat}>
{stat[0].toUpperCase() + stat.slice(1)}
</option>
)
})}
</select>
</StyledCurrentStatSelect>
)
}
export default CurrentStatSelect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment