React showing 0 instead of nothing with short-circuit (&&) conditional component

后端 未结 3 1522
闹比i
闹比i 2020-12-13 05:42

I have the following simple short-circuit statement that should show either a component or nothing:

{profileTypesLoading && }

3条回答
  •  孤街浪徒
    2020-12-13 06:31

    This would solve the problem:

    {!!profileTypesLoading && }
    

    As it will convert 0 to false. The reason is when it's 0 the next condition doesn't get executed and it behaves like a number in JavaScript so double negation helps here.

提交回复
热议问题