最初使 react-bootstrap 警报不可见

Make react-bootstrap Alert invisible initially

我使用的版本:

react@16.8.6
react-bootstrap@1.0.0-beta.8

我正在尝试创建一个最初不可见的警报。 According to the documentation, the show attribute is the right one to use, but it doesn't seem to be working.

这些是我尝试过的方法,但是 none 有效:

<Alert variant="danger" show="false">Passwords must match</Alert>
<Alert variant="danger" defaultShow="false">Passwords must match</Alert>
<Alert variant="danger" show=false>Passwords must match</Alert>
<Alert variant="danger" defaultShow=false>Passwords must match</Alert>

如有任何想法,我们将不胜感激。非常感谢。

您正在为 false 使用字符串。使用带大括号的 javascript false 代替:

<Alert variant="danger" show={false}>Passwords must match</Alert>

尝试像这样将显示从字符串修改为布尔值

<Alert variant="danger" show={false}>Passwords must match</Alert>

您将 false 用作字符串,但 show 属性接受布尔值。使用

show={false}

而不是

show="false"

您可以在状态中使用属性,因此,如果您更改状态,您会强制应用重新呈现,并且会显示警报

<Alert variant="danger" show={this.state.show}>Passwords must match</Alert>