by nonethewiser · 3y ago · 0 comments
Couldn't you put that in a function that returns the correct JSX element or am I misunderstanding the problem? Something like:
renderThing(number) {
if(number > 0) return <div>...</div>
return <div>...</div>
}
const Page = () => {
return <div>{renderThing(someNumber)}</div>
}
Simple ternaries are fine IMO but thats what I do when the logic gets complicated. I never used a nested ternary in that situation, for example.This is because it doesn't get registered as it's own component, so conditionally called children with hooks may cause errors.
So this style of code is fine in react