Skip to content

Instantly share code, notes, and snippets.

@panw
Created September 15, 2016 22:34
Show Gist options
  • Save panw/ef42b2c226d8fa8b30c90ea3702ad211 to your computer and use it in GitHub Desktop.
Save panw/ef42b2c226d8fa8b30c90ea3702ad211 to your computer and use it in GitHub Desktop.
If a React Component was Written in Ruby
class Timeline << React::Component {
def initialize(props) {
super(props)
@state = { tweets: [] }
}
def component_did_mount() {
self.fetchTweets();
}
def fetch_tweets() {
open('/tweets/recent') do |response|
self.setState({tweets: response})
end
}
def render() {
# Assumes JSX exist in Ruby
return (
<section>
<ul>
<% @state.tweets.each do |tweet| %>
<Tweet data=<% tweet %> />
<% end %>
</ul>
</section>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment