I am rendering a page with react and react-bootstrap, with the use of <ListGroup>
and <ListGroupItem>
. The following is my code, and I'm trying to use bsStyle='info'
when the status is not '1'
, and leave it blank when status is '1'
.
<ListGroup>
{tables.map(table => (
<ListGroupItem
key={`table.${table.id}`}
header=(table.name)
bsStyle={table.status !== '1' ? ('info') : ('')}
>
{table.content} -
</ListGroupItem>
))}
</ListGroup>
It rendered properly but keeps getting the following warning due to validation of bsStyle:
Warning: Failed prop type: Invalid prop `bsStyle` of value `` supplied to `ListGroupItem`, expected one of ["success","warning","danger","info"].
There is a workaround to escape the validation by setting bsStyle={null}
. However I can't get it works within the ternary expression. The following code will make it a string bsStyle='{null}'
.
<ListGroup>
{tables.map(table => (
<ListGroupItem
key={`table.${table.id}`}
header=(table.name)
bsStyle={table.status !== '1' ? ('info') : ('{null}')}
>
{table.content} -
</ListGroupItem>
))}
</ListGroup>
What is the proper way to pass {null}
without making it a string?
EDITED: Supposed to be '{null}' and not '{null' up there.
I am rendering a page with react and react-bootstrap, with the use of <ListGroup>
and <ListGroupItem>
. The following is my code, and I'm trying to use bsStyle='info'
when the status is not '1'
, and leave it blank when status is '1'
.
<ListGroup>
{tables.map(table => (
<ListGroupItem
key={`table.${table.id}`}
header=(table.name)
bsStyle={table.status !== '1' ? ('info') : ('')}
>
{table.content} -
</ListGroupItem>
))}
</ListGroup>
It rendered properly but keeps getting the following warning due to validation of bsStyle:
Warning: Failed prop type: Invalid prop `bsStyle` of value `` supplied to `ListGroupItem`, expected one of ["success","warning","danger","info"].
There is a workaround to escape the validation by setting bsStyle={null}
. However I can't get it works within the ternary expression. The following code will make it a string bsStyle='{null}'
.
<ListGroup>
{tables.map(table => (
<ListGroupItem
key={`table.${table.id}`}
header=(table.name)
bsStyle={table.status !== '1' ? ('info') : ('{null}')}
>
{table.content} -
</ListGroupItem>
))}
</ListGroup>
What is the proper way to pass {null}
without making it a string?
EDITED: Supposed to be '{null}' and not '{null' up there.
Share Improve this question edited Jul 3, 2017 at 2:36 Yen Sheng asked Jul 1, 2017 at 16:58 Yen ShengYen Sheng 7251 gold badge14 silver badges28 bronze badges2 Answers
Reset to default 4Your ternary operator's second operand is off:
('{null}')
That evaluates to literally "{null}"
. Try this:
bsStyle={table.status !== '1' ? 'info' : null}
Just use null
plainly, do not wrap it in quotes. Here's a JSFiddle example.
You probably want to ommit whole bsStyle attribute in case status is not different from 1
<ListGroupItem
key={`table.${table.id}`}
header=(table.name)
{...( table.status !== '1' ? {bsStyle:'info'} : {} )}
>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745546618a4632367.html
评论列表(0条)