I have useState
as follows:
const [orderStandard, setOrderStandard] = useState("total");
And based on the value of orderStandard
, I want to give props.
The code below is ButtonGroup
with BootStrap for ReactJS.
https://react-bootstrap.github.io/components/button-group/#button-toolbar-props
<ButtonGroup style={{ height: 35, display: "flex", justifyContent: "center", alignItems: "center", }} > <Button id="order-button" variant="light" style={{ width: 80 }} active onClick={() => setOrderStandard("total")} >
Above, among the props of Button, active
causes the button to be selected.
So I set it as the following conditions.
But it will throw an error. Error message: '...'expected.ts(1005)
So I use ...
<Button id="order-button" variant="light" style={{ width: 80 }} {...(orderStandard == "total" ? active : null)} onClick={() => setOrderStandard("total")} >
But when I write the code above, it says active
props are undefined.
How can I do it?
P粉6701076612024-02-27 15:17:20
You are receiving 'active' is not Defined
because you are trying to use active
as a variable instead of using it as a property of Button
.
Try this