anthonyshort / deku

Render interfaces using pure functions and virtual DOM
https://github.com/anthonyshort/deku/tree/master/docs
3.41k stars 131 forks source link

Question: undefined content in vnodes #403

Closed 11111000000 closed 8 years ago

11111000000 commented 8 years ago

What is a common way to handle undefined content inside tags:

return (
  <div>{ something }</div>
)

which thrown errror if something is undefined.

Now we code like this:

return (
  <div>{ something ? something : '' }</div>
)

but too many hard to maintain conditionals is a pain!

I miss something, or how to implement:

return fixUndefined(
  <div>{ something }</div>
)

...or maybe there is a other, better way to do that and other validations? (may be with redux?)

11111000000 commented 8 years ago

Decomposition:

...
return (<TextField content={something} />)
...

where

const TextField = ({props : {content = ''}})  => 
    (<div class='text-field'>{ content }</div>) 
anthonyshort commented 8 years ago

You can also use a null value. That will be transformed into a noscript tag during the diff.

let something = null
// Some logic...
return (
  <div>{ something }</div>
)