jeudi 7 novembre 2019

How to avoid nested ternary in render?

This is my case:

<Form onSubmit={submit}>
                    {something === 0 ?
                        (someData.length && someData.length > 0) ?
                            doSomething() : null :
                        (someOtherData.length && someOtherData.length > 0) ?
                            doSomethingElse() : null
                    }
</Form>

However, eslint rule is giving me error: Do not nest ternary expressions.

How can this be avoided? Can if - else be written in return (...) which renders data?

Aucun commentaire:

Enregistrer un commentaire