【发布时间】:2021-06-30 05:55:51
【问题描述】:
下面的代码给了我这个错误:
react-dom.development.js:67 警告:收到
false的非布尔属性high。如果要将其写入 DOM,请改为传递字符串:high="false" 或 high={value.toString()}。
我尝试了各种方法,但按钮的颜色不会根据道具值而改变。
import styled from 'styled-components';
const Button=styled.button`
border:none;
background:${(props) => (props.high ? 'red':'orange')};
color:white;
`
export const getStaticProps = async () => {
const res = await fetch('http://localhost:8000/issues');
const data = await res.json();
return {
props: { cards: data }
}
}
const issues = ({cards}) => {
return (
<>
<div className="container">
{cards.map(card => (
<div className="grid-item link" key={card.id}>
<Link href={'/issues/' + card.id}>
<div>
<Button high={card.priority === "high"} className="priority">{ card.priority } Priority</Button>
</div>
</Link>
</div>
))}
</div>
</>
);
}
【问题讨论】:
标签: javascript reactjs next.js