【发布时间】:2020-01-07 20:59:12
【问题描述】:
我有 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;
}
`
【问题讨论】:
标签: javascript reactjs oop styled-components