I am starting playing with ReactJS for my Rails apps.
One of the things I noticed very soon would be using Ruby methods in ReactJS components - typically, what I am using daily, is formatting date, shortening text/strings:
content = this.state.posts.map(post => {
return(
<li key={post.id}>
{post.created_at.strftime('%B')}
{post.message}
</li>
)
});
This will obviously raise an error Uncaught TypeError: post.created_at.strftime is not a function, because I am applying a ruby method on javascript data (I am used to do these operations in Rails views).
What's the correct approach here with /in ReactJS components? Should I pre-prepare the format of data from database in the controller? Or should I research for JS functions to replicate the behavior of the respective Ruby methods?
Or is there a third way to do this a better way?