【问题标题】:Warning: Received `false` for a non-boolean attribute `alt`警告:收到非布尔属性“alt”的“false”
【发布时间】:2021-02-06 03:54:30
【问题描述】:

我正在尝试将道具传递到我配置的样式化组件按钮中,但它显示以下错误:

Warning: Received `false` for a non-boolean attribute `alt`.

这是我配置按钮的地方

const StyledButton = styled.button`
    background-color: ${(props) => (props.alt ? "red" : "white")};
    color: black;
    font: inherit;
    border: 1px solid purple;
    padding: 8px;
    cursor: pointer;

    &:hover {
        background-color: ${(props) => (props.alt ? "salmon" : "lightgreen")};
        color: black;
    }
`;

这是我调用按钮并将值传递给 alt 的地方(仅供参考:showPerson 的值是布尔值):

const Cockpit = (props) => {
    return (
        <div>
            <StyledButton alt={props.showPerson} onClick={() => props.toggle()}>
                Switch Name
            </StyledButton>
        </div>
    );
};

【问题讨论】:

  • alt 是一个官方的 HTML 属性名称。我知道这是一个按钮,而不是图像,但仍然最好为道具使用不同的名称
  • 酷,它已修复。谢谢

标签: reactjs styled-components


【解决方案1】:

alt 是一个官方的 HTML 属性名称。我知道这是一个按钮,而不是图像,但仍然最好为道具使用不同的名称 - Jayce444 1 分钟

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-09
    • 1970-01-01
    • 2019-10-05
    • 1970-01-01
    • 2022-10-13
    • 2022-10-09
    • 2021-06-30
    • 2021-05-10
    相关资源
    最近更新 更多