У меня есть 4 кнопки, которые генерируются с помощью функции моей карты. Когда я нажимаю кнопку, я хочу, чтобы стиль применялся только к этой 1 кнопке. Прямо сейчас стиль применяется ко всем кнопкам.
Где я ошибаюсь?
const MultiChoiceQuestions = props => {
const { multiChoiceArray, handleClick, inputValue, updateInputValue } = props
const [active, setActive] = useState(false)
console.log('state', active)
// () => handleClick(questionChoice)
return (
<ButtonContainer>
{multiChoiceArray.map(questionChoice => {
return (
<Button
active={active}
type="button"
key={questionChoice.id}
onClick={() => setActive(!active)}
>
{questionChoice.text}
</Button>
)
})}
</ButtonContainer>
)
}
const Button = styled.button`
height: 3rem;
width: 20rem;
border-style: solid;
border-width: 1px;
border-color: #c7c7c76b;
background-color: ${props => (props.active ? 'green' : 'white')};
cursor: pointer;
-webkit-appearance: none;
-moz-appearance: none;
border-radius: 6px;
transition: background 250ms ease-in-out, transform 150ms ease;
font-weight: 400;
&:hover {
background-color: #ff00006b;
transform: scale(1.25);
font-weight: 800;
border: none;
}
`