hyper-react
hyper-react copied to clipboard
convert all return values to strings, unless?
Why can't we just convert all values returned by the tag's block to a string?
If I say
li { foo }
and foo is for example a Time
it fails.
I am trying to reproduce the issue, but it seems like passing a Date
as foo won't raise any exception. Would love to help if @fzingg could provide more information.
I am not sure about converting return values to string automatically, but at least we could make the exception raised more clear for debugging.
@zetachang
In fact it doesn't raise any exception for me as well but the value doesn't display at all without the to_s
:
td(width: '33%') { params.post.posttitle }
td(width: '33%') { params.post.description }
td(width: '33%') { params.post.created_at.to_s }
Here Posttile
and description
are displayed but created_at
only displayed with to_s
created_at
is a timestamp
here but I tried with date
and I have the same issue.
I pushed it on a repo : https://github.com/fzingg/hyperloop-eventsapp
@fzingg , thanks for updating the information. Does a exception like the following help?
Exception raised while rendering #<MyComponent:0x203c>:
Instead of String or React::Element, a Time object was returned in one of child building block.
Yes, I think it would be great.
Note the better error message will be in Hyper-React 0.12, plus in Hyper-Component there will also be automatic conversion for the most common types, via the acts_as_string? flag